Skip to content

Commit 7ed4606

Browse files
committed
install: Quiet output of mkfs.vfat and ostree repo init
Just to make the install process look nicer. Signed-off-by: Colin Walters <[email protected]>
1 parent 43f7bf6 commit 7ed4606

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

lib/src/install.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,11 +574,10 @@ fn install_create_rootfs(state: &State) -> Result<RootSetup> {
574574

575575
// Create the EFI system partition, if applicable
576576
if let Some(espdev) = espdev {
577-
Task::new_and_run(
578-
"Creating ESP filesystem",
579-
"mkfs.fat",
580-
[espdev.as_str(), "-n", "EFI-SYSTEM"],
581-
)?;
577+
Task::new("Creating ESP filesystem", "mkfs.fat")
578+
.args([espdev.as_str(), "-n", "EFI-SYSTEM"])
579+
.quiet_output()
580+
.run()?;
582581
let efifs_path = bootfs.join("efi");
583582
std::fs::create_dir(&efifs_path).context("Creating efi dir")?;
584583
mount(&espdev, &efifs_path)?;

lib/src/task.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{
22
ffi::OsStr,
3+
io::Seek,
34
process::{Command, Stdio},
45
};
56

@@ -8,6 +9,7 @@ use anyhow::{Context, Result};
89
pub(crate) struct Task {
910
description: String,
1011
quiet: bool,
12+
quiet_output: bool,
1113
pub(crate) cmd: Command,
1214
}
1315

@@ -23,6 +25,7 @@ impl Task {
2325
Self {
2426
description,
2527
quiet: false,
28+
quiet_output: false,
2629
cmd,
2730
}
2831
}
@@ -32,6 +35,12 @@ impl Task {
3235
self
3336
}
3437

38+
// Do not print stdout/stderr, unless the command fails
39+
pub(crate) fn quiet_output(mut self) -> Self {
40+
self.quiet_output = true;
41+
self
42+
}
43+
3544
pub(crate) fn args<S: AsRef<OsStr>>(mut self, args: impl IntoIterator<Item = S>) -> Self {
3645
self.cmd.args(args);
3746
self
@@ -44,9 +53,21 @@ impl Task {
4453
if !self.quiet {
4554
println!("{description}");
4655
}
56+
let mut output = None;
57+
if self.quiet_output {
58+
let tmpf = tempfile::tempfile()?;
59+
cmd.stdout(Stdio::from(tmpf.try_clone()?));
60+
cmd.stderr(Stdio::from(tmpf.try_clone()?));
61+
output = Some(tmpf);
62+
}
4763
tracing::debug!("exec: {cmd:?}");
4864
let st = cmd.status()?;
4965
if !st.success() {
66+
if let Some(mut output) = output {
67+
output.seek(std::io::SeekFrom::Start(0))?;
68+
let mut stderr = std::io::stderr().lock();
69+
std::io::copy(&mut output, &mut stderr)?;
70+
}
5071
anyhow::bail!("Task {description} failed: {st:?}");
5172
}
5273
Ok(())

0 commit comments

Comments
 (0)