summaryrefslogtreecommitdiffstats
path: root/src/sandbox
diff options
context:
space:
mode:
Diffstat (limited to 'src/sandbox')
-rw-r--r--src/sandbox/loopback.rs30
-rw-r--r--src/sandbox/mod.rs5
2 files changed, 29 insertions, 6 deletions
diff --git a/src/sandbox/loopback.rs b/src/sandbox/loopback.rs
index 1b31b1a..8e9f52d 100644
--- a/src/sandbox/loopback.rs
+++ b/src/sandbox/loopback.rs
@@ -65,12 +65,30 @@ impl Sandbox for LoopbackSandbox {
}
fn run(&self, cmd: &Cmd, on_log: &mut dyn FnMut(&[u8])) -> Result<Exit> {
- let argv0 = cmd
- .argv
- .first()
- .ok_or_else(|| Error::invalid("sandbox command has no argv[0]"))?;
- let mut c = std::process::Command::new(argv0);
- c.args(&cmd.argv[1..]);
+ if cmd.argv.is_empty() {
+ return Err(Error::invalid("sandbox command has no argv[0]"));
+ }
+ // Expand `blob:<digest>` argv elements to the staged blob's path —
+ // the loopback sandbox's blob dir is "inside the sandbox" as much as
+ // anything here is. An unstaged blob is a caller bug and fails closed.
+ let mut argv: Vec<String> = Vec::with_capacity(cmd.argv.len());
+ for a in &cmd.argv {
+ match a.strip_prefix("blob:") {
+ Some(digest) => {
+ let path = self.blob_path(digest)?;
+ if !path.exists() {
+ return Err(Error::fail_closed(format!(
+ "blob {digest} was never staged in sandbox {}",
+ self.id
+ )));
+ }
+ argv.push(path.display().to_string());
+ }
+ None => argv.push(a.clone()),
+ }
+ }
+ let mut c = std::process::Command::new(&argv[0]);
+ c.args(&argv[1..]);
if let Some(dir) = &cmd.cwd {
c.current_dir(dir);
}
diff --git a/src/sandbox/mod.rs b/src/sandbox/mod.rs
index 18c98ad..5be5f4f 100644
--- a/src/sandbox/mod.rs
+++ b/src/sandbox/mod.rs
@@ -37,6 +37,11 @@ pub mod loopback;
/// `Command`-shaped: a remote sandbox must never be handed a shell string, and
/// the environment is the backend's business (see `Config::child_env`), not the
/// caller's.
+///
+/// An argv element of the form `blob:<digest>` names a content-addressed blob
+/// staged with [`Sandbox::put`]: the backend expands it to wherever that blob
+/// materializes inside the sandbox. Callers never name sandbox-local paths —
+/// that is what keeps a loopback step byte-identical to a remote one.
#[derive(Debug, Clone)]
pub struct Cmd {
pub argv: Vec<String>,