Fix ~ (WinAPI) must use Handle::from_path_any() if target path might be a directory

.# [why]

"If you use `from_path()` on a directory, then subsequent queries using that handle will fail."
Instead, use `from_path_any()` which supports opening files or directories.

ref: "Struct winapi_util::Handle" from <https://docs.rs/crate/winapi-util>
This commit is contained in:
Roy Ivy III
2020-01-22 21:11:06 -06:00
parent 1af6e1f757
commit 7a38a26593

View File

@@ -28,7 +28,7 @@ pub fn get_metadata(d: &DirEntry, _use_apparent_size: bool) -> Option<(u64, Opti
use winapi_util::file::information;
use winapi_util::Handle;
let h = Handle::from_path(d.path()).ok()?;
let h = Handle::from_path_any(d.path()).ok()?;
let info = information(&h).ok()?;
Some((
@@ -59,7 +59,7 @@ pub fn get_filesystem(file_path: &str) -> Result<u64, io::Error> {
use winapi_util::file::information;
use winapi_util::Handle;
let h = Handle::from_path(file_path)?;
let h = Handle::from_path_any(file_path)?;
let info = information(&h)?;
Ok(info.volume_serial_number())
}