From 2425856c966c60c8852ab6567949ff7c45a59bdc Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 1 Aug 2025 11:06:03 -0400 Subject: [PATCH] Drop a few more uses of Task It wasn't a useful abstraction in the end for most cases. Signed-off-by: Colin Walters --- crates/lib/src/bootloader.rs | 32 ++++++++++++++++-------------- crates/lib/src/install.rs | 22 +++++++++----------- crates/lib/src/install/baseline.rs | 12 +++++------ 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/crates/lib/src/bootloader.rs b/crates/lib/src/bootloader.rs index 275d035a3..aa07bfe80 100644 --- a/crates/lib/src/bootloader.rs +++ b/crates/lib/src/bootloader.rs @@ -1,8 +1,10 @@ +use std::process::Command; + use anyhow::{anyhow, bail, Context, Result}; +use bootc_utils::CommandRunExt; use camino::Utf8Path; use fn_error_context::context; -use crate::task::Task; use bootc_blockdev::PartitionTable; use bootc_mount as mount; @@ -22,16 +24,15 @@ pub(crate) fn install_via_bootupd( let srcroot = rootfs.join(deployment_path); let devpath = device.path(); - let args = ["backend", "install", "--write-uuid"] - .into_iter() - .chain(verbose) - .chain(bootupd_opts.iter().copied().flatten()) - .chain(["--src-root", srcroot.as_str()]) - .chain(["--device", devpath.as_str(), rootfs.as_str()]); - Task::new("Running bootupctl to install bootloader", "bootupctl") - .args(args) - .verbose() - .run() + println!("Installing bootloader via bootupd"); + Command::new("bootupctl") + .args(["backend", "install", "--write-uuid"]) + .args(verbose) + .args(bootupd_opts.iter().copied().flatten()) + .args(["--src-root", srcroot.as_str()]) + .args(["--device", devpath.as_str(), rootfs.as_str()]) + .log_debug() + .run_inherited_with_cmd_context() } #[context("Installing bootloader using zipl")] @@ -97,8 +98,8 @@ pub(crate) fn install_via_zipl(device: &PartitionTable, boot_uuid: &str) -> Resu let ramdisk = boot_dir.join(initrd).canonicalize_utf8()?; // Execute the zipl command to install bootloader - let zipl_desc = format!("running zipl to install bootloader on {device_path}"); - let zipl_task = Task::new(&zipl_desc, "zipl") + println!("Running zipl on {device_path}"); + Command::new("zipl") .args(["--target", boot_dir.as_str()]) .args(["--image", image.as_str()]) .args(["--ramdisk", ramdisk.as_str()]) @@ -107,6 +108,7 @@ pub(crate) fn install_via_zipl(device: &PartitionTable, boot_uuid: &str) -> Resu .args(["--targettype", "SCSI"]) .args(["--targetblocksize", "512"]) .args(["--targetoffset", &boot_part_offset.to_string()]) - .args(["--add-files", "--verbose"]); - zipl_task.verbose().run().context(zipl_desc) + .args(["--add-files", "--verbose"]) + .log_debug() + .run_inherited_with_cmd_context() } diff --git a/crates/lib/src/install.rs b/crates/lib/src/install.rs index 55a566201..33f851e69 100644 --- a/crates/lib/src/install.rs +++ b/crates/lib/src/install.rs @@ -587,10 +587,9 @@ impl SourceInfo { fn have_selinux_from_repo(root: &Dir) -> Result { let cancellable = ostree::gio::Cancellable::NONE; - let commit = Task::new("Reading ostree commit", "ostree") + let commit = Command::new("ostree") .args(["--repo=/ostree/repo", "rev-parse", "--single"]) - .quiet() - .read()?; + .run_get_string()?; let repo = ostree::Repo::open_at_dir(root.as_fd(), "ostree/repo")?; let root = repo .read_commit(commit.trim(), cancellable) @@ -1071,11 +1070,10 @@ pub(crate) fn finalize_filesystem( .run()?; // Finally, freezing (and thawing) the filesystem will flush the journal, which means the next boot is clean. for a in ["-f", "-u"] { - Task::new("Flushing filesystem journal", "fsfreeze") - .quiet() - .cwd(root)? + Command::new("fsfreeze") + .cwd_dir(root.try_clone()?) .args([a, path.as_str()]) - .run()?; + .run_capture_stderr()?; } Ok(()) } @@ -1115,10 +1113,9 @@ pub(crate) fn setup_tmp_mount() -> Result<()> { } else { // Note we explicitly also don't want a "nosuid" tmp, because that // suppresses our install_t transition - Task::new("Mounting tmpfs /tmp", "mount") + Command::new("mount") .args(["tmpfs", "-t", "tmpfs", "/tmp"]) - .quiet() - .run()?; + .run_capture_stderr()?; } Ok(()) } @@ -1147,10 +1144,9 @@ pub(crate) fn setup_sys_mount(fstype: &str, fspath: &str) -> Result<()> { } // This means the host has this mounted, so we should mount it too - Task::new(format!("Mounting {fstype} {fspath}"), "mount") + Command::new("mount") .args(["-t", fstype, fstype, fspath]) - .quiet() - .run()?; + .run_capture_stderr()?; Ok(()) } diff --git a/crates/lib/src/install/baseline.rs b/crates/lib/src/install/baseline.rs index 567990e1e..1cd48c48f 100644 --- a/crates/lib/src/install/baseline.rs +++ b/crates/lib/src/install/baseline.rs @@ -9,10 +9,12 @@ use std::borrow::Cow; use std::fmt::Display; use std::fmt::Write as _; use std::io::Write; +use std::process::Command; use std::process::Stdio; use anyhow::Ok; use anyhow::{Context, Result}; +use bootc_utils::CommandRunExt; use camino::Utf8Path; use camino::Utf8PathBuf; use cap_std::fs::Dir; @@ -136,13 +138,11 @@ fn mkfs<'a>( Ok(u) } -#[context("Failed to wipe {dev}")] pub(crate) fn wipefs(dev: &Utf8Path) -> Result<()> { - Task::new_and_run( - format!("Wiping device {dev}"), - "wipefs", - ["-a", dev.as_str()], - ) + println!("Wiping device {dev}"); + Command::new("wipefs") + .args(["-a", dev.as_str()]) + .run_inherited_with_cmd_context() } pub(crate) fn udev_settle() -> Result<()> {