about summary refs log tree commit diff
path: root/library/std/src/sys
diff options
context:
space:
mode:
authorChris Denton <chris@chrisdenton.dev>2023-10-10 17:45:30 +0100
committerChris Denton <chris@chrisdenton.dev>2023-10-10 17:56:31 +0100
commit367d7ed67df16fcc4c26b186e5910605ca3748ed (patch)
treed7dd4897381762107c7d6374278290a4407010ee /library/std/src/sys
parent5b88d659f8c2428536589d4bd36b9099d53a6815 (diff)
downloadrust-367d7ed67df16fcc4c26b186e5910605ca3748ed.tar.gz
rust-367d7ed67df16fcc4c26b186e5910605ca3748ed.zip
On Windows make readdir error on the empty path
Diffstat (limited to 'library/std/src/sys')
-rw-r--r--library/std/src/sys/windows/fs.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs
index 0113196b824..c5897cc9266 100644
--- a/library/std/src/sys/windows/fs.rs
+++ b/library/std/src/sys/windows/fs.rs
@@ -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 as i32));
+    }
     let root = p.to_path_buf();
     let star = p.join("*");
     let path = maybe_verbatim(&star)?;