Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/walkdir.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2018-08-25 06:20:33 +0300
committerAndrew Gallant <jamslam@gmail.com>2018-08-25 06:38:09 +0300
commit8b72d93227a8f0635c8ffdc3a3d390a192ab956a (patch)
tree8b0ae8054d2b68666c77cbe1c333f892ac32ece6
parent64399797d19c17fa63628795b933a1eeb914a1a1 (diff)
windows: replace winapi ffi with winapi-util
We do still need winapi for a std-library work-around.
-rw-r--r--Cargo.toml5
-rw-r--r--src/lib.rs10
-rw-r--r--src/windows.rs34
3 files changed, 10 insertions, 39 deletions
diff --git a/Cargo.toml b/Cargo.toml
index d6a4a0e..ff39c42 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,7 +20,10 @@ same-file = "1.0.1"
[target.'cfg(windows)'.dependencies.winapi]
version = "0.3"
-features = ["std", "fileapi", "winbase", "winnt"]
+features = ["std", "winnt"]
+
+[target.'cfg(windows)'.dependencies.winapi-util]
+version = "0.1.1"
[dev-dependencies]
docopt = "1.0.1"
diff --git a/src/lib.rs b/src/lib.rs
index d60c2d7..0d04a5d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -112,6 +112,8 @@ extern crate rand;
extern crate same_file;
#[cfg(windows)]
extern crate winapi;
+#[cfg(windows)]
+extern crate winapi_util;
use std::cmp::{Ordering, min};
use std::error;
@@ -132,8 +134,6 @@ pub use unix::DirEntryExt;
mod tests;
#[cfg(unix)]
mod unix;
-#[cfg(windows)]
-mod windows;
/// Like try, but for iterators that return [`Option<Result<_, _>>`].
///
@@ -1666,8 +1666,10 @@ fn device_num<P: AsRef<Path>>(path: P)-> std::io::Result<u64> {
#[cfg(windows)]
fn device_num<P: AsRef<Path>>(path: P) -> std::io::Result<u64> {
- windows::windows_file_handle_info(path)
- .map(|info| info.dwVolumeSerialNumber as u64)
+ use winapi_util::{Handle, file};
+
+ let h = Handle::from_path_any(path)?;
+ file::information(h).map(|info| info.volume_serial_number())
}
#[cfg(not(any(unix, windows)))]
diff --git a/src/windows.rs b/src/windows.rs
deleted file mode 100644
index 85b726e..0000000
--- a/src/windows.rs
+++ /dev/null
@@ -1,34 +0,0 @@
-use std::fs::OpenOptions;
-use std::io::Error;
-use std::mem;
-use std::os::windows::fs::OpenOptionsExt;
-use std::os::windows::io::AsRawHandle;
-use std::path::Path;
-
-use winapi::um::fileapi::{
- BY_HANDLE_FILE_INFORMATION,
- GetFileInformationByHandle,
-};
-use winapi::um::winbase::FILE_FLAG_BACKUP_SEMANTICS;
-
-/// Return metadata for the file at the given path.
-pub fn windows_file_handle_info<P: AsRef<Path>>(
- path: P,
-) -> Result<BY_HANDLE_FILE_INFORMATION, Error> {
- // The FILE_FLAG_BACKUP_SEMANTICS flag is needed to open directories
- // https://msdn.microsoft.com/en-us/library/windows/desktop/aa365258(v=vs.85).aspx
- let file = OpenOptions::new()
- .create(false)
- .write(false)
- .read(true)
- .custom_flags(FILE_FLAG_BACKUP_SEMANTICS)
- .open(path)?;
-
- unsafe {
- let mut info = mem::zeroed();
- if GetFileInformationByHandle(file.as_raw_handle(), &mut info) == 0 {
- return Err(Error::last_os_error());
- }
- Ok(info)
- }
-}