Skip to content

Commit 367d7ed

Browse files
committed
On Windows make readdir error on the empty path
1 parent 5b88d65 commit 367d7ed

File tree

1 file changed

+8
-0
lines changed
  • library/std/src/sys/windows

1 file changed

+8
-0
lines changed

library/std/src/sys/windows/fs.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,14 @@ impl DirBuilder {
10661066
}
10671067

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

0 commit comments

Comments
 (0)