From 0a258829f75d3d3c161bef423b46a8ed79ffba9b Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sat, 25 May 2024 23:35:53 +0200 Subject: [PATCH] feat: without prefix Signed-off-by: kjuulh --- crates/flux-releaser/src/services/archive.rs | 15 +++++++++++---- .../src/services/flux_local_cluster.rs | 6 ++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/crates/flux-releaser/src/services/archive.rs b/crates/flux-releaser/src/services/archive.rs index 4a42c8e..d0c6da0 100644 --- a/crates/flux-releaser/src/services/archive.rs +++ b/crates/flux-releaser/src/services/archive.rs @@ -1,7 +1,9 @@ -#[derive(Clone)] +#[derive(Clone, Default)] pub struct Archive {} -use std::io::Cursor; +use std::{io::Cursor, path::Path}; + +use anyhow::Context; use super::file_reader::Files; @@ -10,7 +12,7 @@ impl Archive { Self {} } - pub async fn create_archive(&self, files: Files) -> anyhow::Result { + pub async fn create_archive(&self, prefix: &Path, files: Files) -> anyhow::Result { tracing::trace!("archiving files: {}", files.len()); let buffer = Vec::new(); @@ -27,7 +29,12 @@ impl Archive { tar_builder.append_file(&rel, &mut fd)?; } else { tracing::trace!("archiving file: {}", abs_file_path.display()); - tar_builder.append_file(&abs_file_path, &mut fd)?; + tar_builder.append_file( + abs_file_path + .strip_prefix(prefix) + .context("failed to strip prefix from path")?, + &mut fd, + )?; } } diff --git a/crates/flux-releaser/src/services/flux_local_cluster.rs b/crates/flux-releaser/src/services/flux_local_cluster.rs index 22d826d..c4e6d2e 100644 --- a/crates/flux-releaser/src/services/flux_local_cluster.rs +++ b/crates/flux-releaser/src/services/flux_local_cluster.rs @@ -40,8 +40,10 @@ impl FluxLocalClusterManager { &self, include: impl Into, ) -> anyhow::Result { - let files = self.file_reader.read_files(include.into()).await?; - let archive = self.archive.create_archive(files).await?; + let include = include.into(); + + let files = self.file_reader.read_files(include.clone()).await?; + let archive = self.archive.create_archive(&include, files).await?; let upload_id = self.flux_uploader.upload_archive(archive).await?; Ok(upload_id)