Skip to content

Commit c8cc3f2

Browse files
committed
address PR feedback
Signed-off-by: Terence Lee <hone02@gmail.com>
1 parent 7faf588 commit c8cc3f2

4 files changed

Lines changed: 12 additions & 21 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/system-reinstall-bootc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ log = { workspace = true }
2828
rustix = { workspace = true }
2929
serde = { workspace = true, features = ["derive"] }
3030
serde_json = { workspace = true }
31+
shlex = { workspace = true }
3132
tempfile = { workspace = true }
3233
tracing = { workspace = true }
3334
uzers = { workspace = true }

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! The main entrypoint for the bootc system reinstallation CLI
22
3-
use anyhow::{Context, Result, ensure};
4-
use bootc_utils::CommandRunExt;
3+
use anyhow::{ensure, Context, Result};
4+
use bootc_utils::{CommandRunExt, ResultExt};
55
use clap::Parser;
66
use fn_error_context::context;
77
use rustix::process::getuid;
@@ -52,8 +52,7 @@ impl ReinstallOptsArgs {
5252
.iter()
5353
.find_map(|path| {
5454
os_release::get_bootc_image_from_file(path)
55-
.ok()
56-
.flatten()
55+
.log_err_default()
5756
.filter(|s| !s.is_empty())
5857
})
5958
.ok_or_else(|| {

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

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,13 @@ fn parse_bootc_image_from_reader<R: BufRead>(reader: R) -> Result<Option<String>
1717
continue;
1818
}
1919

20-
if let Some((key, value)) = line.split_once('=') {
21-
if key.trim() == "BOOTC_IMAGE" {
22-
let value = value.trim();
23-
24-
if value.starts_with('"') && value.ends_with('"') && value.len() >= 2 {
25-
let unquoted = &value[1..value.len() - 1];
26-
let processed = unquoted
27-
.replace(r#"\""#, "\"")
28-
.replace(r#"\\"#, "\\")
29-
.replace(r#"\$"#, "$")
30-
.replace(r#"\`"#, "`");
31-
last_found = Some(processed);
32-
} else if value.starts_with('\'') && value.ends_with('\'') && value.len() >= 2 {
33-
last_found = Some(value[1..value.len() - 1].to_string());
34-
} else {
35-
last_found = Some(value.to_string());
36-
}
20+
let Some((key, value)) = line.split_once('=') else {
21+
continue;
22+
};
23+
24+
if key.trim() == "BOOTC_IMAGE" {
25+
if let Some(unquoted) = shlex::split(value).and_then(|mut values| values.pop()) {
26+
last_found = Some(unquoted);
3727
}
3828
}
3929
}

0 commit comments

Comments
 (0)