Skip to content

Commit

Permalink
kargs: Factor out helper for filename matching
Browse files Browse the repository at this point in the history
Since we have two different read paths.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Jun 28, 2024
1 parent 6ea1802 commit 6000633
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/src/kargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ struct Config {
match_architectures: Option<Vec<String>>,
}

impl Config {
/// Return true if the filename is one we should parse.
fn filename_matches(name: &str) -> bool {
matches!(Utf8Path::new(name).extension(), Some("toml"))
}
}

/// Load and parse all bootc kargs.d files in the specified root, returning
/// a combined list.
fn get_kargs_in_root(d: &Dir, sys_arch: &str) -> Result<Vec<String>> {
Expand All @@ -43,7 +50,7 @@ fn get_kargs_in_root(d: &Dir, sys_arch: &str) -> Result<Vec<String>> {
let name = name
.to_str()
.ok_or_else(|| anyhow::anyhow!("Invalid non-UTF8 filename: {name:?}"))?;
if !matches!(Utf8Path::new(name).extension(), Some("toml")) {
if !Config::filename_matches(name) {
continue;
}
let buf = d.read_to_string(name)?;
Expand Down Expand Up @@ -72,9 +79,10 @@ fn get_kargs_from_ostree(
} else {
continue;
};
if !name.ends_with(".toml") {
if !Config::filename_matches(name) {
continue;
}

let fetched_child = fetched_iter.child(&fetched_info);
let fetched_child = fetched_child
.downcast::<ostree::RepoFile>()
Expand Down

0 comments on commit 6000633

Please sign in to comment.