Skip to content

Commit

Permalink
On Windows make readdir error on the empty path
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDenton committed Oct 10, 2023
1 parent 5b88d65 commit 01f025c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions library/std/src/sys/windows/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,14 @@ impl DirBuilder {
}

pub fn readdir(p: &Path) -> io::Result<ReadDir> {
// We push a `*` to the end of the path which cause the empty path to be
// treated as the current directory. So, for consistency with other platforms,
// we explicitly error on the empty path.
if p.as_os_str().is_empty() {
// Return an error code consistent with other ways of opening files.
// E.g. fs::metadata or File::open.
return Err(io::Error::from_raw_os_error(c::ERROR_PATH_NOT_FOUND));
}
let root = p.to_path_buf();
let star = p.join("*");
let path = maybe_verbatim(&star)?;
Expand Down

0 comments on commit 01f025c

Please sign in to comment.