summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-04-12 19:35:18 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-04-12 19:35:18 +0200
commitcc56b73b84b2c60c1b96c2adccfbbe2415a8ff19 (patch)
treeb7eda5456eb9a18b5bd8b6150a415216fe138096
parent876f3be733c174ac83a889aa78f2463f875a08c0 (diff)
parentc3eca5be23510eb2f508d679d659e6805dae7d7f (diff)
Merge branch 'no-outputs-directory'
-rw-r--r--doc/containers.md2
-rw-r--r--src/consts.rs1
-rw-r--r--src/filestore/path.rs37
-rw-r--r--src/filestore/staging.rs17
4 files changed, 37 insertions, 20 deletions
diff --git a/doc/containers.md b/doc/containers.md
index cbb62a0..52f4b4a 100644
--- a/doc/containers.md
+++ b/doc/containers.md
@@ -15,7 +15,7 @@ on. Those are listed here.
1. Dependencies are named `/inputs/<packagename>-<packageversion>.pkg` inside the container
2. Sources are named `/inputs/src-<hashsum>.source`
-3. Outputs are expected to be named `/outputs/<packagename>-<packageversion>.pkg`
+3. Outputs are expected to be written to the `/outputs` directory
The reason for the names lies in the artifact parsing mechanism.
If the package is named differently, the artifact parsing mechanism is not able
diff --git a/src/consts.rs b/src/consts.rs
index 8891f81..5c6dbc4 100644
--- a/src/consts.rs
+++ b/src/consts.rs
@@ -16,6 +16,7 @@ pub const INPUTS_DIR_PATH: &str = "/inputs";
/// The path to the directory inside the container where the outputs of a compile job must be
/// located after the script was run
pub const OUTPUTS_DIR_PATH: &str = "/outputs";
+pub const OUTPUTS_DIR_NAME: &str = "outputs";
/// The path where the script that is executed inside the container is copied to.
pub const SCRIPT_PATH: &str = "/script";
diff --git a/src/filestore/path.rs b/src/filestore/path.rs
index e8c7a26..4de941b 100644
--- a/src/filestore/path.rs
+++ b/src/filestore/path.rs
@@ -88,11 +88,44 @@ 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,
{
- ar.unpack(&self.0).map_err(Error::from)
+ ar.entries()?
+ .into_iter()
+ .map_err(Error::from)
+ .filter_ok(|entry| entry.header().entry_type() == tar::EntryType::Regular)
+ .and_then_ok(|mut entry| -> Result<_> {
+ let path = 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::<PathBuf>();
+
+ log::trace!("Path = '{:?}'", path);
+ let unpack_dest = self.0.join(&path);
+ log::trace!("Unpack to = '{:?}'", unpack_dest);
+
+ entry.unpack(unpack_dest)
+ .map(|_| path)
+ .map_err(Error::from)
+ })
+ .collect::<Result<Vec<_>>>()
}
}
diff --git a/src/filestore/staging.rs b/src/filestore/staging.rs
index 73701cd..af62980 100644
--- a/src/filestore/staging.rs
+++ b/src/filestore/staging.rs
@@ -52,27 +52,10 @@ impl StagingStore {
.try_concat()
.await
.and_then(|bytes| {
- let mut archive = tar::Archive::new(&bytes[..]);
-
- let outputs = archive
- .entries()
- .context("Fetching entries from tar archive")?
- .map(|ent| {
- let p = ent?
- .path()
- .context("Getting path of TAR entry")?
- .into_owned();
- Ok(p)
- })
- .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()