fix(build/oci): Propagate passAsFile files into the build sandbox.
fixes #87 Change-Id: Ia8109ae678bddb1072e15f6a3ed63e3e3c862b6a Reviewed-on: https://cl.snix.dev/c/snix/+/30238 Autosubmit: Vova Kryachko <v.kryachko@gmail.com> Reviewed-by: Florian Klink <flokli@flokli.de> Tested-by: besadii Reviewed-by: Yureka <snix@yuka.dev>
This commit is contained in:
parent
e8642518f8
commit
9942014989
1 changed files with 30 additions and 2 deletions
|
|
@ -1,7 +1,9 @@
|
||||||
//! Module to create an OCI runtime bundle for a given [BuildRequest].
|
//! Module to create an OCI runtime bundle for a given [BuildRequest].
|
||||||
use std::{
|
use std::{
|
||||||
|
ffi::OsStr,
|
||||||
fs,
|
fs,
|
||||||
path::{Path, PathBuf},
|
io::Write,
|
||||||
|
path::{Component, Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::scratch_name;
|
use super::scratch_name;
|
||||||
|
|
@ -39,7 +41,33 @@ pub(crate) fn make_bundle<'a>(
|
||||||
for p in request.scratch_paths.iter() {
|
for p in request.scratch_paths.iter() {
|
||||||
let scratch_path = scratch_root.join(scratch_name(p));
|
let scratch_path = scratch_root.join(scratch_name(p));
|
||||||
debug!(scratch_path=?scratch_path, path=?p, "about to create scratch dir");
|
debug!(scratch_path=?scratch_path, path=?p, "about to create scratch dir");
|
||||||
fs::create_dir_all(scratch_path).context("Unable to create scratch dir")?;
|
fs::create_dir_all(scratch_path.clone()).context("Unable to create scratch dir")?;
|
||||||
|
|
||||||
|
// TODO(#152): this is a hack, in the general case we may not have the "build" directory and additional files
|
||||||
|
// may not have /build prefix. But in practice today snix_build.rs is the only user of the builder and
|
||||||
|
// it always sets up a /build scratch and populates all additional_files with the /build prefix.
|
||||||
|
// For now this unblocks builds, but worth improving in the future.
|
||||||
|
if p == Path::new("build") {
|
||||||
|
for file in request.additional_files.iter() {
|
||||||
|
if file.path.components().count() < 2
|
||||||
|
|| file.path.components().next() != Some(Component::Normal(OsStr::new("build")))
|
||||||
|
{
|
||||||
|
Err(std::io::Error::other(
|
||||||
|
"Additional files must start with build/",
|
||||||
|
))?
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove build/ prefix
|
||||||
|
let p = file.path.components().skip(1).collect::<PathBuf>();
|
||||||
|
if let Some(parent) = p.parent() {
|
||||||
|
fs::create_dir_all(scratch_path.clone().join(parent))
|
||||||
|
.context("Failed to create dir for additional file")?;
|
||||||
|
}
|
||||||
|
let p = scratch_path.join(p);
|
||||||
|
let mut out = std::fs::File::create(p).context("could not create file")?;
|
||||||
|
out.write_all(&file.contents)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue