Add option to pass through arguments to brwap, use shlex for dry-run
This commit is contained in:
10
src/lib.rs
10
src/lib.rs
@@ -26,6 +26,7 @@ pub struct SandboxConfig {
|
||||
pub extra_rw: Vec<PathBuf>,
|
||||
pub extra_ro: Vec<PathBuf>,
|
||||
pub mask: Vec<PathBuf>,
|
||||
pub bwrap_args: Vec<String>,
|
||||
pub command: PathBuf,
|
||||
pub command_args: Vec<OsString>,
|
||||
pub chdir: PathBuf,
|
||||
@@ -63,9 +64,16 @@ pub fn run(config: SandboxConfig) -> Result<(), SandboxError> {
|
||||
let mut cmd = sandbox::build_command(&config)?;
|
||||
|
||||
if config.dry_run {
|
||||
println!("{:?}", cmd);
|
||||
println!("{}", shell_quote_command(&cmd));
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Err(SandboxError::Io(cmd.exec()))
|
||||
}
|
||||
|
||||
fn shell_quote_command(cmd: &std::process::Command) -> String {
|
||||
let prog = cmd.get_program().to_string_lossy();
|
||||
let args = cmd.get_args().map(|a| a.to_string_lossy());
|
||||
let all: Vec<_> = std::iter::once(prog).chain(args).collect();
|
||||
shlex::try_join(all.iter().map(|s| s.as_ref())).unwrap()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user