diff --git a/Cargo.lock b/Cargo.lock index 393a967f..ac897292 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,6 +260,7 @@ version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19eb8e3d71996828751c1ed3908a439639752ac6bdc874e41469ef7fc15fbd7f" dependencies = [ + "camino", "cap-primitives", "io-extras", "io-lifetimes", @@ -283,6 +284,7 @@ version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53880047c3f37cd64947775f0526795498d614182603a718c792616b762ce777" dependencies = [ + "camino", "cap-std", "rand", "rustix", diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 5e6a6081..efb93af3 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -20,7 +20,7 @@ ostree-ext = { version = "0.14.0" } chrono = { version = "0.4.38", features = ["serde"] } clap = { version= "4.5.4", features = ["derive","cargo"] } clap_mangen = { version = "0.2.20", optional = true } -cap-std-ext = "4" +cap-std-ext = { version = "4.0.1", features = ["fs_utf8"] } hex = "^0.4.3" fn-error-context = "0.2.1" gvariant = "0.5.0" diff --git a/lib/src/kargs.rs b/lib/src/kargs.rs index 8840dfbe..90119ab3 100644 --- a/lib/src/kargs.rs +++ b/lib/src/kargs.rs @@ -1,7 +1,9 @@ use anyhow::{Context, Result}; use camino::Utf8Path; use cap_std_ext::cap_std::fs::Dir; +use cap_std_ext::cap_std::fs_utf8::Dir as DirUtf8; use cap_std_ext::dirext::CapStdExtDirExt; +use cap_std_ext::dirext::CapStdExtDirExtUtf8; use ostree::gio; use ostree_ext::ostree; use ostree_ext::ostree::Deployment; @@ -35,23 +37,16 @@ impl Config { /// a combined list. pub(crate) fn get_kargs_in_root(d: &Dir, sys_arch: &str) -> Result> { // If the directory doesn't exist, that's OK. - let Some(d) = d.open_dir_optional("usr/lib/bootc/kargs.d")? else { + let Some(d) = d + .open_dir_optional("usr/lib/bootc/kargs.d")? + .map(DirUtf8::from_cap_std) + else { return Ok(Default::default()); }; let mut ret = Vec::new(); - // Read all the entries - let mut entries = d.entries()?.collect::>>()?; - // cc https://github.com/rust-lang/rust/issues/85573 re the allocation-per-comparison here - entries.sort_by_key(|a| a.file_name()); - for ent in entries { - let name = ent.file_name(); - let name = name - .to_str() - .ok_or_else(|| anyhow::anyhow!("Invalid non-UTF8 filename: {name:?}"))?; - if !Config::filename_matches(name) { - continue; - } - let buf = d.read_to_string(name)?; + let entries = d.filenames_filtered_sorted(|_, name| Config::filename_matches(name))?; + for name in entries { + let buf = d.read_to_string(&name)?; let kargs = parse_kargs_toml(&buf, sys_arch).with_context(|| format!("Parsing {name}"))?; ret.extend(kargs) }