Skip to content

Commit

Permalink
fs: add and export constant COMMON_SKIP_DIRS
Browse files Browse the repository at this point in the history
  • Loading branch information
phip1611 committed May 12, 2023
1 parent 49f69a6 commit 1aab1f0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
7 changes: 6 additions & 1 deletion uefi/src/fs/dir_entry_iter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
//! Module for directory iteration. See [`UefiDirectoryIter`].
use super::*;
use crate::Result;
use crate::{CStr16, Result};
use alloc::boxed::Box;
use uefi_macros::cstr16;

/// Common skip dirs in UEFI/FAT-style file systems.
pub const COMMON_SKIP_DIRS: &[&CStr16] = &[cstr16!("."), cstr16!("..")];

/// Iterates over the entries of an UEFI directory. It returns boxed values of
/// type [`UefiFileInfo`].
Expand All @@ -14,6 +18,7 @@ pub struct UefiDirectoryIter(UefiDirectoryHandle);

impl UefiDirectoryIter {
/// Constructor.
#[must_use]
pub fn new(handle: UefiDirectoryHandle) -> Self {
Self(handle)
}
Expand Down
5 changes: 1 addition & 4 deletions uefi/src/fs/file_system/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use core::fmt;
use core::fmt::{Debug, Formatter};
use core::ops::Deref;
use log::debug;
use uefi::CStr16;
use uefi_macros::cstr16;

/// Return type for public [`FileSystem`] operations.
pub type FileSystemResult<T> = Result<T, Error>;
Expand Down Expand Up @@ -186,13 +184,12 @@ impl<'a> FileSystem<'a> {
/// Removes a directory at this path, after removing all its contents. Use
/// carefully!
pub fn remove_dir_all(&mut self, path: impl AsRef<Path>) -> FileSystemResult<()> {
const SKIP_DIRS: [&CStr16; 2] = [cstr16!("."), cstr16!("..")];
let path = path.as_ref();
for file_info in self
.read_dir(path)?
.filter_map(|file_info_result| file_info_result.ok())
{
if SKIP_DIRS.contains(&file_info.file_name()) {
if COMMON_SKIP_DIRS.contains(&file_info.file_name()) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion uefi/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ mod file_system;
mod path;
mod uefi_types;

pub use dir_entry_iter::*;
pub use file_system::*;
pub use path::*;

use dir_entry_iter::*;
use uefi_types::*;

0 comments on commit 1aab1f0

Please sign in to comment.