Skip to content

Commit f08bae1

Browse files
committed
Change manual Command .status to use run_inherited
This re-implements 675bbf6 in a cleaner way using the new `run_inherited` API. Signed-off-by: Colin Walters <walters@verbum.org>
1 parent ae3a087 commit f08bae1

File tree

7 files changed

+20
-30
lines changed

7 files changed

+20
-30
lines changed

rust/src/bwrap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
33
// SPDX-License-Identifier: Apache-2.0 OR MIT
44

5-
use bootc_internal_utils::CommandRunExt;
65
use crate::cxxrsutil::*;
76
use crate::ffi::BubblewrapMutability;
87
use crate::normalization;
98
use anyhow::{Context, Result};
9+
use bootc_internal_utils::CommandRunExt;
1010
use camino::Utf8Path;
1111
use camino::Utf8PathBuf;
1212
use cap_std::fs::Dir;

rust/src/compose.rs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ use ostree_ext::ostree::MutableTree;
2929
use ostree_ext::{container as ostree_container, glib};
3030
use ostree_ext::{oci_spec, ostree};
3131

32-
use bootc_internal_utils::CommandRunExt;
3332
use crate::containers_storage::Mount;
3433
use crate::cxxrsutil::{CxxResult, FFIGObjectWrapper};
3534
use crate::isolation::self_command;
3635
use crate::{RPMOSTREE_RPMDB_LOCATION, RPMOSTREE_SYSIMAGE_RPMDB};
36+
use bootc_internal_utils::CommandRunExt;
3737

3838
const SYSROOT: &str = "sysroot";
3939
const USR: &str = "usr";
@@ -374,7 +374,7 @@ impl BuildChunkedOCIOpts {
374374
};
375375
let manifest_data = manifest_data_tmpfile.as_ref().map(|t| t.path());
376376

377-
let st = crate::isolation::self_command()
377+
crate::isolation::self_command()
378378
.args([
379379
"compose",
380380
"container-encapsulate",
@@ -397,10 +397,8 @@ impl BuildChunkedOCIOpts {
397397
manifest.as_os_str(),
398398
]
399399
}))
400-
.status()?;
401-
if !st.success() {
402-
anyhow::bail!("Failed to run compose container-encapsulate: {st:?}");
403-
}
400+
.run_inherited()
401+
.context("Invoking compose container-encapsulate")?;
404402

405403
drop(rootfs);
406404
// Ensure our tempdir is only dropped now
@@ -750,7 +748,7 @@ impl RootfsOpts {
750748
};
751749

752750
// Just build the root filesystem tree
753-
let st = self_command()
751+
self_command()
754752
.args([
755753
"compose",
756754
"install",
@@ -777,10 +775,8 @@ impl RootfsOpts {
777775
// it won't be able to. We should lower the xattr stripping into
778776
// rpm-ostree ideally.
779777
.env("DRACUT_NO_XATTR", "1")
780-
.status()?;
781-
if !st.success() {
782-
anyhow::bail!("Executing compose install: {st:?}");
783-
}
778+
.run_inherited()
779+
.context("Executing compose install")?;
784780

785781
// Clear everything in the tempdir; at this point we may have hardlinks into
786782
// the pkgcache repo, which we don't need because we're producing a flat
@@ -1207,7 +1203,7 @@ pub(crate) fn compose_image(args: Vec<String>) -> CxxResult<()> {
12071203
compose_args_extra.extend(["--source-root", path.as_str()]);
12081204
}
12091205

1210-
let st = self_command()
1206+
self_command()
12111207
.args([
12121208
"compose",
12131209
"tree",
@@ -1226,10 +1222,7 @@ pub(crate) fn compose_image(args: Vec<String>) -> CxxResult<()> {
12261222
.args(opt.lockfile_strict.then_some("--ex-lockfile-strict"))
12271223
.args(compose_args_extra)
12281224
.arg(opt.manifest.as_str())
1229-
.status()?;
1230-
if !st.success() {
1231-
return Err(format!("Failed to run compose tree: {st:?}").into());
1232-
}
1225+
.run_inherited()?;
12331226

12341227
if !changed_path.exists() {
12351228
return Ok(());
@@ -1265,7 +1258,7 @@ pub(crate) fn compose_image(args: Vec<String>) -> CxxResult<()> {
12651258
})
12661259
.transpose()?;
12671260

1268-
let st = self_command()
1261+
self_command()
12691262
.args(["compose", "container-encapsulate"])
12701263
.args(label_args)
12711264
.args(previous_arg)
@@ -1277,10 +1270,7 @@ pub(crate) fn compose_image(args: Vec<String>) -> CxxResult<()> {
12771270
commitid.as_str(),
12781271
tempdest.as_deref().unwrap_or(target_imgref.as_str()),
12791272
])
1280-
.status()?;
1281-
if !st.success() {
1282-
return Err(format!("Failed to run compose container-encapsulate: {st:?}").into());
1283-
}
1273+
.run_inherited()?;
12841274

12851275
if let Some(tempdest) = tempdest {
12861276
let mut c = Command::new("skopeo");

rust/src/composepost.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
use crate::bwrap;
99
use crate::bwrap::Bubblewrap;
1010
use crate::capstdext::dirbuilder_from_mode;
11-
use bootc_internal_utils::CommandRunExt;
1211
use crate::cxxrsutil::*;
1312
use crate::ffi::BubblewrapMutability;
1413
use crate::ffiutil::ffi_dirfd;
1514
use crate::normalization;
1615
use crate::treefile::{OptUsrLocal, Treefile};
1716
use anyhow::{anyhow, bail, Context, Result};
17+
use bootc_internal_utils::CommandRunExt;
1818
use camino::{Utf8Path, Utf8PathBuf};
1919
use cap_std::fs::Dir;
2020
use cap_std::fs_utf8::Dir as Utf8Dir;

rust/src/container.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ use ostree_ext::oci_spec::image::{Arch, Os, PlatformBuilder};
3030
use ostree_ext::prelude::*;
3131
use ostree_ext::{gio, oci_spec, ostree};
3232

33-
use bootc_internal_utils::CommandRunExt;
3433
use crate::cxxrsutil::FFIGObjectReWrap;
3534
use crate::fsutil::{self, FileHelpers, ResolvedOstreePaths};
3635
use crate::progress::progress_task;
3736
use crate::CxxResult;
37+
use bootc_internal_utils::CommandRunExt;
3838

3939
const COMPONENT_XATTR: &CStr = c"user.component";
4040

rust/src/initramfs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! Generate an "overlay" initramfs image
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33

4-
use bootc_internal_utils::CommandRunExt;
54
use crate::cxxrsutil::*;
65
use anyhow::{Context, Result};
6+
use bootc_internal_utils::CommandRunExt;
77
use camino::Utf8Path;
88
use cap_std::fs::Dir;
99
use cap_std::io_lifetimes::AsFilelike;

rust/src/testutils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
//! This backs the hidden `rpm-ostree testutils` CLI. Subject
1010
//! to change.
1111
12-
use bootc_internal_utils::CommandRunExt;
1312
use crate::cxxrsutil::*;
1413
use anyhow::{Context, Result};
14+
use bootc_internal_utils::CommandRunExt;
1515
use cap_std::fs::FileType;
1616
use cap_std::fs::{Dir, MetadataExt, Permissions, PermissionsExt};
1717
use cap_std_ext::cap_std;

rust/src/treefile.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
use crate::{compose_postprocess_scripts, cxxrsutil::*};
2323
use anyhow::{anyhow, bail, Context, Result};
24+
use bootc_internal_utils::CommandRunExt;
2425
use camino::{Utf8Path, Utf8PathBuf};
2526
use cap_std::fs::MetadataExt as _;
2627
use cap_std_ext::cap_std::fs::Dir;
@@ -851,10 +852,9 @@ impl Treefile {
851852
if let Some(d) = self.directory.as_deref() {
852853
cmd.env("RPMOSTREE_WORKDIR", d);
853854
}
854-
let st = cmd.cwd_dir(rootfs.try_clone()?).status()?;
855-
if !st.success() {
856-
return Err(anyhow!("Failed to execute {name}: {st}"));
857-
}
855+
cmd.cwd_dir(rootfs.try_clone()?)
856+
.run_inherited()
857+
.with_context(|| format!("Failed to execute {name}"))?;
858858
}
859859
Ok(())
860860
}

0 commit comments

Comments
 (0)