|
1 | 1 | use anyhow::{Context, Result};
|
2 | 2 | use camino::Utf8Path;
|
3 | 3 | use cap_std_ext::cap_std::fs::Dir;
|
| 4 | +use cap_std_ext::cap_std::fs_utf8::Dir as DirUtf8; |
4 | 5 | use cap_std_ext::dirext::CapStdExtDirExt;
|
| 6 | +use cap_std_ext::dirext::CapStdExtDirExtUtf8; |
5 | 7 | use ostree::gio;
|
6 | 8 | use ostree_ext::ostree;
|
7 | 9 | use ostree_ext::ostree::Deployment;
|
@@ -35,23 +37,16 @@ impl Config {
|
35 | 37 | /// a combined list.
|
36 | 38 | pub(crate) fn get_kargs_in_root(d: &Dir, sys_arch: &str) -> Result<Vec<String>> {
|
37 | 39 | // 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 { |
39 | 44 | return Ok(Default::default());
|
40 | 45 | };
|
41 | 46 | 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)?; |
55 | 50 | let kargs = parse_kargs_toml(&buf, sys_arch).with_context(|| format!("Parsing {name}"))?;
|
56 | 51 | ret.extend(kargs)
|
57 | 52 | }
|
|
0 commit comments