Skip to content

Commit 6000633

Browse files
committed
kargs: Factor out helper for filename matching
Since we have two different read paths. Signed-off-by: Colin Walters <[email protected]>
1 parent 6ea1802 commit 6000633

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/src/kargs.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ struct Config {
2424
match_architectures: Option<Vec<String>>,
2525
}
2626

27+
impl Config {
28+
/// Return true if the filename is one we should parse.
29+
fn filename_matches(name: &str) -> bool {
30+
matches!(Utf8Path::new(name).extension(), Some("toml"))
31+
}
32+
}
33+
2734
/// Load and parse all bootc kargs.d files in the specified root, returning
2835
/// a combined list.
2936
fn get_kargs_in_root(d: &Dir, sys_arch: &str) -> Result<Vec<String>> {
@@ -43,7 +50,7 @@ fn get_kargs_in_root(d: &Dir, sys_arch: &str) -> Result<Vec<String>> {
4350
let name = name
4451
.to_str()
4552
.ok_or_else(|| anyhow::anyhow!("Invalid non-UTF8 filename: {name:?}"))?;
46-
if !matches!(Utf8Path::new(name).extension(), Some("toml")) {
53+
if !Config::filename_matches(name) {
4754
continue;
4855
}
4956
let buf = d.read_to_string(name)?;
@@ -72,9 +79,10 @@ fn get_kargs_from_ostree(
7279
} else {
7380
continue;
7481
};
75-
if !name.ends_with(".toml") {
82+
if !Config::filename_matches(name) {
7683
continue;
7784
}
85+
7886
let fetched_child = fetched_iter.child(&fetched_info);
7987
let fetched_child = fetched_child
8088
.downcast::<ostree::RepoFile>()

0 commit comments

Comments
 (0)