From a52b3a1206ca8ff387e3931d6b35b7b194d11617 Mon Sep 17 00:00:00 2001 From: Rolf Karp Date: Sun, 19 Nov 2017 10:29:29 +0100 Subject: [PATCH] Make API the same on all platforms, simplify Linux compilation (#3) * Generalize API for Windows to make it the same for all platforms * Avoid compiling Windows dependencies on Linux, fix warning --- src/fs.rs | 5 +++-- src/lib.rs | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index b9eeaf1..852191a 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -25,7 +25,7 @@ struct RmdirContext<'a> { /// remove_dir_all("./temp/").unwrap(); /// } /// ``` -pub fn remove_dir_all(path: &Path) -> io::Result<()> { +pub fn remove_dir_all>(path: P) -> io::Result<()> { // On Windows it is not enough to just recursively remove the contents of a // directory and then the directory itself. Deleting does not happen // instantaneously, but is scheduled. @@ -69,6 +69,7 @@ pub fn remove_dir_all(path: &Path) -> io::Result<()> { // Open the path once to get the canonical path, file type and attributes. let (path, metadata) = { + let path = path.as_ref(); let mut opts = OpenOptions::new(); opts.access_mode(FILE_READ_ATTRIBUTES); opts.custom_flags(FILE_FLAG_BACKUP_SEMANTICS | @@ -158,7 +159,7 @@ fn rename(file: &File, new: &Path, replace: bool) -> io::Result<()> { unsafe { // Thanks to alignment guarantees on Windows this works // (8 for 32-bit and 16 for 64-bit) - let mut info = data.as_mut_ptr() as *mut FILE_RENAME_INFO; + let info = data.as_mut_ptr() as *mut FILE_RENAME_INFO; // The type of ReplaceIfExists is BOOL, but it actually expects a // BOOLEAN. This means true is -1, not c::TRUE. (*info).ReplaceIfExists = if replace { -1 } else { FALSE }; diff --git a/src/lib.rs b/src/lib.rs index 606fb39..67b0548 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,6 @@ +#[cfg(windows)] extern crate winapi; +#[cfg(windows)] extern crate kernel32 as kernel; #[cfg(windows)] -- 2.16.1