Skip to content

Commit 89635a8

Browse files
authored
Merge pull request #676 from cgwalters/fs-utf8
kargs: Introduce usage of fs_utf8
2 parents 63f593d + 80b6673 commit 89635a8

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

Cargo.lock

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

lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ostree-ext = { version = "0.14.0" }
2020
chrono = { version = "0.4.38", features = ["serde"] }
2121
clap = { version= "4.5.4", features = ["derive","cargo"] }
2222
clap_mangen = { version = "0.2.20", optional = true }
23-
cap-std-ext = "4"
23+
cap-std-ext = { version = "4.0.1", features = ["fs_utf8"] }
2424
hex = "^0.4.3"
2525
fn-error-context = "0.2.1"
2626
gvariant = "0.5.0"

lib/src/kargs.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use anyhow::{Context, Result};
22
use camino::Utf8Path;
33
use cap_std_ext::cap_std::fs::Dir;
4+
use cap_std_ext::cap_std::fs_utf8::Dir as DirUtf8;
45
use cap_std_ext::dirext::CapStdExtDirExt;
6+
use cap_std_ext::dirext::CapStdExtDirExtUtf8;
57
use ostree::gio;
68
use ostree_ext::ostree;
79
use ostree_ext::ostree::Deployment;
@@ -35,23 +37,16 @@ impl Config {
3537
/// a combined list.
3638
pub(crate) fn get_kargs_in_root(d: &Dir, sys_arch: &str) -> Result<Vec<String>> {
3739
// If the directory doesn't exist, that's OK.
38-
let Some(d) = d.open_dir_optional("usr/lib/bootc/kargs.d")? else {
40+
let Some(d) = d
41+
.open_dir_optional("usr/lib/bootc/kargs.d")?
42+
.map(DirUtf8::from_cap_std)
43+
else {
3944
return Ok(Default::default());
4045
};
4146
let mut ret = Vec::new();
42-
// Read all the entries
43-
let mut entries = d.entries()?.collect::<std::io::Result<Vec<_>>>()?;
44-
// cc https://github.com/rust-lang/rust/issues/85573 re the allocation-per-comparison here
45-
entries.sort_by_key(|a| a.file_name());
46-
for ent in entries {
47-
let name = ent.file_name();
48-
let name = name
49-
.to_str()
50-
.ok_or_else(|| anyhow::anyhow!("Invalid non-UTF8 filename: {name:?}"))?;
51-
if !Config::filename_matches(name) {
52-
continue;
53-
}
54-
let buf = d.read_to_string(name)?;
47+
let entries = d.filenames_filtered_sorted(|_, name| Config::filename_matches(name))?;
48+
for name in entries {
49+
let buf = d.read_to_string(&name)?;
5550
let kargs = parse_kargs_toml(&buf, sys_arch).with_context(|| format!("Parsing {name}"))?;
5651
ret.extend(kargs)
5752
}

0 commit comments

Comments
 (0)