Skip to content

Commit 897b579

Browse files
committed
install: Use some fs_utf8 bits
This makes the code slightly more consise. Not prep for anything, just a cleanup. Signed-off-by: Colin Walters <[email protected]>
1 parent 89635a8 commit 897b579

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

lib/src/install.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use camino::Utf8Path;
2525
use camino::Utf8PathBuf;
2626
use cap_std::fs::{Dir, MetadataExt};
2727
use cap_std_ext::cap_std;
28+
use cap_std_ext::cap_std::fs_utf8::DirEntry as DirEntryUtf8;
2829
use cap_std_ext::prelude::CapStdExtDirExt;
2930
use chrono::prelude::*;
3031
use clap::ValueEnum;
@@ -1344,27 +1345,21 @@ pub(crate) async fn install_to_disk(mut opts: InstallToDiskOpts) -> Result<()> {
13441345
#[context("Verifying empty rootfs")]
13451346
fn require_empty_rootdir(rootfs_fd: &Dir) -> Result<()> {
13461347
for e in rootfs_fd.entries()? {
1347-
let e = e?;
1348-
let name = e.file_name();
1349-
let name = name
1350-
.to_str()
1351-
.ok_or_else(|| anyhow!("Invalid non-UTF8 filename: {name:?}"))?;
1348+
let e = DirEntryUtf8::from_cap_std(e?);
1349+
let name = e.file_name()?;
13521350
if name == LOST_AND_FOUND {
13531351
continue;
13541352
}
13551353
// There must be a boot directory (that is empty)
13561354
if name == BOOT {
13571355
let mut entries = rootfs_fd.read_dir(BOOT)?;
13581356
if let Some(e) = entries.next() {
1359-
let e = e?;
1360-
let name = e.file_name();
1361-
let name = name
1362-
.to_str()
1363-
.ok_or_else(|| anyhow!("Invalid non-UTF8 filename: {name:?}"))?;
1364-
if matches!(name, LOST_AND_FOUND | crate::bootloader::EFI_DIR) {
1357+
let e = DirEntryUtf8::from_cap_std(e?);
1358+
let name = e.file_name()?;
1359+
if matches!(name.as_str(), LOST_AND_FOUND | crate::bootloader::EFI_DIR) {
13651360
continue;
13661361
}
1367-
anyhow::bail!("Non-empty boot directory, found {name:?}");
1362+
anyhow::bail!("Non-empty boot directory, found {name}");
13681363
}
13691364
} else {
13701365
anyhow::bail!("Non-empty root filesystem; found {name:?}");

0 commit comments

Comments
 (0)