diff options
| author | bors <bors@rust-lang.org> | 2023-10-23 05:38:33 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-10-23 05:38:33 +0000 |
| commit | aec4741d42e10673e7d5fe0f1c96d407801884e8 (patch) | |
| tree | 54a51ae4e9910a3fcac8a97dbc23f96aec939de0 | |
| parent | 62fae2305e5f3a959bd6ad6c20608c118e93648a (diff) | |
| parent | 367d7ed67df16fcc4c26b186e5910605ca3748ed (diff) | |
| download | rust-aec4741d42e10673e7d5fe0f1c96d407801884e8.tar.gz rust-aec4741d42e10673e7d5fe0f1c96d407801884e8.zip | |
Auto merge of #116606 - ChrisDenton:empty, r=dtolnay
On Windows make `read_dir` error on the empty path This makes Windows consistent with other platforms. Note that this should not be taken to imply any decision on #114149 has been taken. However it was felt that while there is a lack of libs-api consensus, we should be consistent across platforms in the meantime. This is a change in behaviour for Windows so will also need an fcp before merging. r? libs-api
| -rw-r--r-- | library/std/src/sys/windows/fs.rs | 8 |
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 6ded683aade..22f2b1007ef 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)?; |
