Skip to content

Commit

Permalink
new api judge a path if is a dir
Browse files Browse the repository at this point in the history
  • Loading branch information
lhw2002426 committed Apr 22, 2024
1 parent e8d702a commit bf8ad02
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,32 @@ impl<'a, IO: ReadWriteSeek, TP: TimeProvider, OCC: OemCpConverter> Dir<'a, IO, T
Err(Error::NotFound) //("No such file or directory"))
}

/// judge if a path is a file or dir
///
/// `path` is a '/' separated directory path relative to self directory.
///
/// # Errors
///
/// Errors that can be returned:
///
/// * `Error::NotFound` will be returned if `path` does not point to any existing directory entry.
pub fn check_path_type(&self, path: &str) -> Result<Option<bool>, Error<IO::Error>> {
let (name, rest_opt) = split_path(path);
if let Some(rest) = rest_opt {
let e = self.find_entry(name, Some(true), None)?;
return e.to_dir().check_path_type(rest);
}
// judge path if is a dir
for r in self.iter() {
let e = r?;
// compare name ignoring case
if e.eq_name(name) {
return Ok(Some(e.is_dir()))
}
}
Err(Error::NotFound)
}

#[allow(clippy::type_complexity)]
pub(crate) fn find_volume_entry(&self) -> Result<Option<DirEntry<'a, IO, TP, OCC>>, Error<IO::Error>> {
for r in DirIter::new(self.stream.clone(), self.fs, false) {
Expand Down

0 comments on commit bf8ad02

Please sign in to comment.