diff options
author | Colin Walters <walters@verbum.org> | 2023-05-10 09:21:45 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2023-05-10 14:02:09 -0400 |
commit | dc23b9389bcd66e0f34db2ace1a0a95e4a9c3d54 (patch) | |
tree | 50ed8c133bdc3f77067d6ac7aab1c055a5f8873b | |
parent | 8a2993a9d01cc358e4c2d936ca132174aabdc714 (diff) | |
download | ostree-dc23b9389bcd66e0f34db2ace1a0a95e4a9c3d54.tar.gz |
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.
-rw-r--r-- | tests/inst/Cargo.toml | 1 | ||||
-rw-r--r-- | tests/inst/src/treegen.rs | 10 |
2 files changed, 5 insertions, 6 deletions
diff --git a/tests/inst/Cargo.toml b/tests/inst/Cargo.toml index 02fc3cbf..c8773ad3 100644 --- a/tests/inst/Cargo.toml +++ b/tests/inst/Cargo.toml @@ -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" } diff --git a/tests/inst/src/treegen.rs b/tests/inst/src/treegen.rs index 77161140..88bd0b7a 100644 --- a/tests/inst/src/treegen.rs +++ b/tests/inst/src/treegen.rs @@ -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") } |