Skip to content

Commit 825f7ac

Browse files
cgwaltersckyrouac
authored andcommitted
Drop a few more uses of Task
It wasn't a useful abstraction in the end for most cases. Signed-off-by: Colin Walters <[email protected]>
1 parent 4e455d6 commit 825f7ac

File tree

3 files changed

+32
-34
lines changed

3 files changed

+32
-34
lines changed

crates/lib/src/bootloader.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
use std::process::Command;
2+
13
use anyhow::{anyhow, bail, Context, Result};
4+
use bootc_utils::CommandRunExt;
25
use camino::Utf8Path;
36
use fn_error_context::context;
47

5-
use crate::task::Task;
68
use bootc_blockdev::PartitionTable;
79
use bootc_mount as mount;
810

@@ -22,16 +24,15 @@ pub(crate) fn install_via_bootupd(
2224

2325
let srcroot = rootfs.join(deployment_path);
2426
let devpath = device.path();
25-
let args = ["backend", "install", "--write-uuid"]
26-
.into_iter()
27-
.chain(verbose)
28-
.chain(bootupd_opts.iter().copied().flatten())
29-
.chain(["--src-root", srcroot.as_str()])
30-
.chain(["--device", devpath.as_str(), rootfs.as_str()]);
31-
Task::new("Running bootupctl to install bootloader", "bootupctl")
32-
.args(args)
33-
.verbose()
34-
.run()
27+
println!("Installing bootloader via bootupd");
28+
Command::new("bootupctl")
29+
.args(["backend", "install", "--write-uuid"])
30+
.args(verbose)
31+
.args(bootupd_opts.iter().copied().flatten())
32+
.args(["--src-root", srcroot.as_str()])
33+
.args(["--device", devpath.as_str(), rootfs.as_str()])
34+
.log_debug()
35+
.run_inherited_with_cmd_context()
3536
}
3637

3738
#[context("Installing bootloader using zipl")]
@@ -97,8 +98,8 @@ pub(crate) fn install_via_zipl(device: &PartitionTable, boot_uuid: &str) -> Resu
9798
let ramdisk = boot_dir.join(initrd).canonicalize_utf8()?;
9899

99100
// Execute the zipl command to install bootloader
100-
let zipl_desc = format!("running zipl to install bootloader on {device_path}");
101-
let zipl_task = Task::new(&zipl_desc, "zipl")
101+
println!("Running zipl on {device_path}");
102+
Command::new("zipl")
102103
.args(["--target", boot_dir.as_str()])
103104
.args(["--image", image.as_str()])
104105
.args(["--ramdisk", ramdisk.as_str()])
@@ -107,6 +108,7 @@ pub(crate) fn install_via_zipl(device: &PartitionTable, boot_uuid: &str) -> Resu
107108
.args(["--targettype", "SCSI"])
108109
.args(["--targetblocksize", "512"])
109110
.args(["--targetoffset", &boot_part_offset.to_string()])
110-
.args(["--add-files", "--verbose"]);
111-
zipl_task.verbose().run().context(zipl_desc)
111+
.args(["--add-files", "--verbose"])
112+
.log_debug()
113+
.run_inherited_with_cmd_context()
112114
}

crates/lib/src/install.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -587,10 +587,9 @@ impl SourceInfo {
587587
fn have_selinux_from_repo(root: &Dir) -> Result<bool> {
588588
let cancellable = ostree::gio::Cancellable::NONE;
589589

590-
let commit = Task::new("Reading ostree commit", "ostree")
590+
let commit = Command::new("ostree")
591591
.args(["--repo=/ostree/repo", "rev-parse", "--single"])
592-
.quiet()
593-
.read()?;
592+
.run_get_string()?;
594593
let repo = ostree::Repo::open_at_dir(root.as_fd(), "ostree/repo")?;
595594
let root = repo
596595
.read_commit(commit.trim(), cancellable)
@@ -1071,11 +1070,10 @@ pub(crate) fn finalize_filesystem(
10711070
.run()?;
10721071
// Finally, freezing (and thawing) the filesystem will flush the journal, which means the next boot is clean.
10731072
for a in ["-f", "-u"] {
1074-
Task::new("Flushing filesystem journal", "fsfreeze")
1075-
.quiet()
1076-
.cwd(root)?
1073+
Command::new("fsfreeze")
1074+
.cwd_dir(root.try_clone()?)
10771075
.args([a, path.as_str()])
1078-
.run()?;
1076+
.run_capture_stderr()?;
10791077
}
10801078
Ok(())
10811079
}
@@ -1115,10 +1113,9 @@ pub(crate) fn setup_tmp_mount() -> Result<()> {
11151113
} else {
11161114
// Note we explicitly also don't want a "nosuid" tmp, because that
11171115
// suppresses our install_t transition
1118-
Task::new("Mounting tmpfs /tmp", "mount")
1116+
Command::new("mount")
11191117
.args(["tmpfs", "-t", "tmpfs", "/tmp"])
1120-
.quiet()
1121-
.run()?;
1118+
.run_capture_stderr()?;
11221119
}
11231120
Ok(())
11241121
}
@@ -1147,10 +1144,9 @@ pub(crate) fn setup_sys_mount(fstype: &str, fspath: &str) -> Result<()> {
11471144
}
11481145

11491146
// This means the host has this mounted, so we should mount it too
1150-
Task::new(format!("Mounting {fstype} {fspath}"), "mount")
1147+
Command::new("mount")
11511148
.args(["-t", fstype, fstype, fspath])
1152-
.quiet()
1153-
.run()?;
1149+
.run_capture_stderr()?;
11541150

11551151
Ok(())
11561152
}

crates/lib/src/install/baseline.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ use std::borrow::Cow;
99
use std::fmt::Display;
1010
use std::fmt::Write as _;
1111
use std::io::Write;
12+
use std::process::Command;
1213
use std::process::Stdio;
1314

1415
use anyhow::Ok;
1516
use anyhow::{Context, Result};
17+
use bootc_utils::CommandRunExt;
1618
use camino::Utf8Path;
1719
use camino::Utf8PathBuf;
1820
use cap_std::fs::Dir;
@@ -136,13 +138,11 @@ fn mkfs<'a>(
136138
Ok(u)
137139
}
138140

139-
#[context("Failed to wipe {dev}")]
140141
pub(crate) fn wipefs(dev: &Utf8Path) -> Result<()> {
141-
Task::new_and_run(
142-
format!("Wiping device {dev}"),
143-
"wipefs",
144-
["-a", dev.as_str()],
145-
)
142+
println!("Wiping device {dev}");
143+
Command::new("wipefs")
144+
.args(["-a", dev.as_str()])
145+
.run_inherited_with_cmd_context()
146146
}
147147

148148
pub(crate) fn udev_settle() -> Result<()> {

0 commit comments

Comments
 (0)