Skip to content

Commit dbf5dac

Browse files
committed
Move bootc_has_clean out of reinstall_command and into run() in
main.rs, so the pull and capability-check steps are clearly distinct and sequenced Signed-off-by: Juan Gomez <1766933+judavi@users.noreply.github.com>
1 parent d6b4f1f commit dbf5dac

2 files changed

Lines changed: 23 additions & 15 deletions

File tree

crates/system-reinstall-bootc/src/main.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use bootc_utils::CommandRunExt;
55
use clap::Parser;
66
use fn_error_context::context;
77
use rustix::process::getuid;
8+
use std::time::Duration;
89

910
mod btrfs;
1011
mod config;
@@ -54,11 +55,24 @@ fn run() -> Result<()> {
5455

5556
podman::ensure_podman_installed()?;
5657

57-
//pull image early so it can be inspected, e.g. to check for cloud-init
58+
// Pull phase: explicitly pull the image before any other operations that use it.
59+
// This ensures no implicit pulls happen in later steps (e.g. capability check).
5860
podman::pull_if_not_present(&opts.image)?;
5961

6062
println!();
6163

64+
// Capability check phase: run after the image is guaranteed to be present locally.
65+
let spinner = indicatif::ProgressBar::new_spinner();
66+
spinner.set_style(
67+
indicatif::ProgressStyle::default_spinner()
68+
.template("{spinner} {msg}")
69+
.expect("Failed to parse spinner template"),
70+
);
71+
spinner.set_message("Checking image capabilities...");
72+
spinner.enable_steady_tick(Duration::from_millis(150));
73+
let has_clean = podman::bootc_has_clean(&opts.image)?;
74+
spinner.finish_and_clear();
75+
6276
let ssh_key_file = tempfile::NamedTempFile::new()?;
6377
let ssh_key_file_path = ssh_key_file
6478
.path()
@@ -71,7 +85,8 @@ fn run() -> Result<()> {
7185

7286
prompt::mount_warning()?;
7387

74-
let mut reinstall_podman_command = podman::reinstall_command(&opts, ssh_key_file_path)?;
88+
let mut reinstall_podman_command =
89+
podman::reinstall_command(&opts, ssh_key_file_path, has_clean)?;
7590

7691
println!();
7792
println!("Going to run command:");

crates/system-reinstall-bootc/src/podman.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ use super::ROOT_KEY_MOUNT_POINT;
44
use anyhow::{Context, Result, ensure};
55
use bootc_utils::CommandRunExt;
66
use fn_error_context::context;
7-
use std::time::Duration;
87
use std::process::Command;
98
use which::which;
109

1110
#[context("bootc_has_clean")]
12-
fn bootc_has_clean(image: &str) -> Result<bool> {
11+
pub(crate) fn bootc_has_clean(image: &str) -> Result<bool> {
1312
let output = Command::new("podman")
1413
.args([
1514
"run",
@@ -26,7 +25,11 @@ fn bootc_has_clean(image: &str) -> Result<bool> {
2625
}
2726

2827
#[context("reinstall_command")]
29-
pub(crate) fn reinstall_command(opts: &ReinstallOpts, ssh_key_file: &str) -> Result<Command> {
28+
pub(crate) fn reinstall_command(
29+
opts: &ReinstallOpts,
30+
ssh_key_file: &str,
31+
has_clean: bool,
32+
) -> Result<Command> {
3033
let mut podman_command_and_args = [
3134
// We use podman to run the bootc container. This might change in the future to remove the
3235
// podman dependency.
@@ -81,16 +84,6 @@ pub(crate) fn reinstall_command(opts: &ReinstallOpts, ssh_key_file: &str) -> Res
8184
// bootc system for the first time.
8285
// This only happens if the bootc version in the image >= 1.1.8 (this is when the cleanup
8386
// feature was introduced)
84-
let spinner = indicatif::ProgressBar::new_spinner();
85-
spinner.set_style(
86-
indicatif::ProgressStyle::default_spinner()
87-
.template("{spinner} {msg}")
88-
.unwrap(),
89-
);
90-
spinner.set_message("Checking image capabilities...");
91-
spinner.enable_steady_tick(Duration::from_millis(150));
92-
let has_clean = bootc_has_clean(&opts.image)?;
93-
spinner.finish_and_clear();
9487
if has_clean {
9588
bootc_command_and_args.push("--cleanup".to_string());
9689
}

0 commit comments

Comments
 (0)