summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-04-12 19:10:42 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-04-12 19:34:36 +0200
commitc3eca5be23510eb2f508d679d659e6805dae7d7f (patch)
tree566694196860566ea6ced23db39e640f0eadb027
parent3537f8e1d174f2ce422c9024a9e0d6df87ad9207 (diff)
Remove duplicated code
This patch rewrites the unpacking of the tar from the stream in a way so that the unpacking function returns the written pathes and therefore we don't have to pass over the tar twice. Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r--src/filestore/path.rs13
-rw-r--r--src/filestore/staging.rs30
2 files changed, 9 insertions, 34 deletions
diff --git a/src/filestore/path.rs b/src/filestore/path.rs
index 3d74992..4de941b 100644
--- a/src/filestore/path.rs
+++ b/src/filestore/path.rs
@@ -88,7 +88,13 @@ impl StoreRoot {
.and_then_ok(ArtifactPath::new)
}
- pub(in crate::filestore) fn unpack_archive_here<R>(&self, mut ar: tar::Archive<R>) -> Result<()>
+ /// Unpack a tar archive in this location
+ ///
+ /// This function unpacks the provided tar archive "butido-style" in the location pointed to by
+ /// `self` and returns the written pathes.
+ ///
+ /// The function filteres out the "/output" directory (that's what is meant by "butido-style").
+ pub(in crate::filestore) fn unpack_archive_here<R>(&self, mut ar: tar::Archive<R>) -> Result<Vec<PathBuf>>
where
R: std::io::Read,
{
@@ -112,15 +118,14 @@ impl StoreRoot {
.collect::<PathBuf>();
log::trace!("Path = '{:?}'", path);
- let unpack_dest = self.0.join(path);
+ let unpack_dest = self.0.join(&path);
log::trace!("Unpack to = '{:?}'", unpack_dest);
entry.unpack(unpack_dest)
- .map(|_| ())
+ .map(|_| path)
.map_err(Error::from)
})
.collect::<Result<Vec<_>>>()
- .map(|_| ())
}
}
diff --git a/src/filestore/staging.rs b/src/filestore/staging.rs
index 9f60d32..af62980 100644
--- a/src/filestore/staging.rs
+++ b/src/filestore/staging.rs
@@ -17,9 +17,6 @@ use anyhow::anyhow;
use futures::stream::Stream;
use indicatif::ProgressBar;
use log::trace;
-use resiter::AndThen;
-use resiter::Filter;
-use resiter::Map;
use result_inspect::ResultInspect;
use crate::filestore::path::ArtifactPath;
@@ -55,37 +52,10 @@ impl StagingStore {
.try_concat()
.await
.and_then(|bytes| {
- let mut archive = tar::Archive::new(&bytes[..]);
-
- let outputs = archive.entries()?
- .map_err(Error::from)
- .filter_ok(|entry| entry.header().entry_type() == tar::EntryType::Regular)
- .and_then_ok(|entry| {
- let entry = entry
- .path()
- .context("Getting path from entry in Archive")?
- .components()
- .filter(|comp| {
- log::trace!("Filtering path component: '{:?}'", comp);
- let osstr = std::ffi::OsStr::new(crate::consts::OUTPUTS_DIR_NAME);
- match comp {
- std::path::Component::Normal(s) => *s != osstr,
- _ => true,
- }
- })
- .collect::<std::path::PathBuf>();
-
- Ok(entry)
- })
- .inspect(|p| trace!("Path in tar archive: {:?}", p))
- .collect::<Result<Vec<_>>>()
- .context("Collecting outputs of TAR archive")?;
-
trace!("Unpacking archive to {}", dest.display());
dest.unpack_archive_here(tar::Archive::new(&bytes[..]))
.context("Unpacking TAR")
.map_err(Error::from)
- .map(|_| outputs)
})
.context("Concatenating the output bytestream")?
.into_iter()