Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kargs: Introduce usage of fs_utf8 #676

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 9 additions & 14 deletions lib/src/kargs.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -35,23 +37,16 @@ impl Config {
/// a combined list.
pub(crate) fn get_kargs_in_root(d: &Dir, sys_arch: &str) -> Result<Vec<String>> {
// 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::<std::io::Result<Vec<_>>>()?;
// 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)
}
Expand Down