make modifications as per reviews
This commit is contained in:
parent
2241d16189
commit
e26f213050
1 changed files with 25 additions and 21 deletions
|
@ -1069,6 +1069,13 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> {
|
||||||
let mut wfd = mem::zeroed();
|
let mut wfd = mem::zeroed();
|
||||||
let find_handle = c::FindFirstFileW(path.as_ptr(), &mut wfd);
|
let find_handle = c::FindFirstFileW(path.as_ptr(), &mut wfd);
|
||||||
|
|
||||||
|
if find_handle != c::INVALID_HANDLE_VALUE {
|
||||||
|
Ok(ReadDir {
|
||||||
|
handle: FindNextFileHandle(find_handle),
|
||||||
|
root: Arc::new(root),
|
||||||
|
first: Some(wfd),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
// The status `ERROR_FILE_NOT_FOUND` is returned by the `FindFirstFileW` function
|
// The status `ERROR_FILE_NOT_FOUND` is returned by the `FindFirstFileW` function
|
||||||
// if no matching files can be found, but not necessarily that the path to find the
|
// if no matching files can be found, but not necessarily that the path to find the
|
||||||
// files in does not exist.
|
// files in does not exist.
|
||||||
|
@ -1080,8 +1087,8 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> {
|
||||||
// returned by the `FindNextFileW` function.
|
// returned by the `FindNextFileW` function.
|
||||||
//
|
//
|
||||||
// See issue #120040: https://github.com/rust-lang/rust/issues/120040.
|
// See issue #120040: https://github.com/rust-lang/rust/issues/120040.
|
||||||
let last_error = Error::last_os_error();
|
let last_error = api::get_last_error();
|
||||||
if last_error.raw_os_error().unwrap() == c::ERROR_FILE_NOT_FOUND as i32 && p.exists() {
|
if last_error.code == c::ERROR_FILE_NOT_FOUND {
|
||||||
return Ok(ReadDir {
|
return Ok(ReadDir {
|
||||||
handle: FindNextFileHandle(find_handle),
|
handle: FindNextFileHandle(find_handle),
|
||||||
root: Arc::new(root),
|
root: Arc::new(root),
|
||||||
|
@ -1089,14 +1096,11 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if find_handle != c::INVALID_HANDLE_VALUE {
|
// Just return the error constructed from the raw OS error if the above is not the case.
|
||||||
Ok(ReadDir {
|
//
|
||||||
handle: FindNextFileHandle(find_handle),
|
// Note: `ERROR_PATH_NOT_FOUND` would have been returned by the `FindFirstFileW` function
|
||||||
root: Arc::new(root),
|
// when the path to search in does not exist in the first place.
|
||||||
first: Some(wfd),
|
Err(Error::from_raw_os_error(last_error.code as i32));
|
||||||
})
|
|
||||||
} else {
|
|
||||||
Err(last_error)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue