tests/inst: Add xshell and use it in one place

I've deprecated sh-inline; in the end I think it is better
to minimize the amount of bash code we have.  xshell solves
the core convenience problem of taking local variables and mapping
them to command arguments.

A full port would be nontrivial; this just starts the ball
rolling.
This commit is contained in:
Colin Walters 2023-05-10 09:21:45 -04:00
parent 8a2993a9d0
commit dc23b9389b
2 changed files with 5 additions and 6 deletions

View File

@ -37,6 +37,7 @@ strum = "0.18.0"
strum_macros = "0.18.0"
# See discussion in https://github.com/coreos/rpm-ostree/pull/2569#issuecomment-780569188
rpmostree-client = { git = "https://github.com/coreos/rpm-ostree", tag = "v2021.3" }
xshell = "0.2.3"
# This one I might publish to crates.io, not sure yet
with-procspawn-tempdir = { git = "https://github.com/cgwalters/with-procspawn-tempdir" }

View File

@ -4,11 +4,11 @@ use cap_std_ext::cap_std;
use cap_std_ext::dirext::*;
use cap_std_ext::rustix::fs::MetadataExt;
use rand::Rng;
use sh_inline::bash;
use std::fs::File;
use std::io::prelude::*;
use std::os::unix::fs::FileExt as UnixFileExt;
use std::path::Path;
use xshell::cmd;
use crate::test::*;
@ -129,6 +129,7 @@ pub(crate) fn update_os_tree<P: AsRef<Path>>(
ostref: &str,
percentage: u32,
) -> Result<()> {
let sh = xshell::Shell::new()?;
assert!(percentage > 0 && percentage <= 100);
let repo_path = repo_path.as_ref();
let tempdir = tempfile::tempdir_in(repo_path.join("tmp"))?;
@ -149,9 +150,6 @@ pub(crate) fn update_os_tree<P: AsRef<Path>>(
}
assert!(mutated > 0);
println!("Mutated ELF files: {}", mutated);
bash!("ostree --repo=${repo} commit --consume -b ${ostref} --base=${ostref} --tree=dir=${tempdir} --owner-uid 0 --owner-gid 0 --selinux-policy-from-base --link-checkout-speedup --no-bindings --no-xattrs",
repo = repo_path,
ostref = ostref,
tempdir = tempdir.path()).context("Failed to commit updated content")?;
Ok(())
let tempdir = tempdir.path();
cmd!(sh, "ostree --repo={repo_path} commit --consume -b {ostref} --base={ostref} --tree=dir={tempdir} --owner-uid 0 --owner-gid 0 --selinux-policy-from-base --link-checkout-speedup --no-bindings --no-xattrs").run().context("Failed to commit updated content")
}