Skip to content

Commit

Permalink
Implement delete and delete_all for windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturKovacs committed Oct 21, 2020
1 parent fedeb83 commit d9a25c8
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/windows.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ffi::OsString;
use std::os::windows::ffi::OsStrExt;
use std::path::Path;
use std::path::{Path, PathBuf};

use winapi::{
shared::minwindef::UINT,
Expand All @@ -19,16 +19,8 @@ pub fn is_implemented() -> bool {
true
}

pub fn remove_all<I, T>(paths: I) -> Result<(), Error>
where
I: IntoIterator<Item = T>,
T: AsRef<Path>,
pub fn remove_all_canonicalized(full_paths: Vec<PathBuf>) -> Result<(), Error>
{
let paths = paths.into_iter();
let full_paths = paths
.map(|x| x.as_ref().canonicalize())
.collect::<Result<Vec<_>, _>>()
.map_err(|e| Error::CanonicalizePath { code: e.raw_os_error() })?;
let mut wide_paths = Vec::with_capacity(full_paths.len());
for path in full_paths.iter() {
let mut os_string = OsString::from(path);
Expand Down Expand Up @@ -66,6 +58,19 @@ where
}
}

pub fn remove_all<I, T>(paths: I) -> Result<(), Error>
where
I: IntoIterator<Item = T>,
T: AsRef<Path>,
{
let paths = paths.into_iter();
let full_paths = paths
.map(|x| x.as_ref().canonicalize())
.collect::<Result<Vec<_>, _>>()
.map_err(|e| Error::CanonicalizePath { code: e.raw_os_error() })?;
remove_all_canonicalized(full_paths)
}

/// See https://docs.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-_shfileopstructa
pub fn remove<T: AsRef<Path>>(path: T) -> Result<(), Error> {
remove_all(&[path])
Expand Down

0 comments on commit d9a25c8

Please sign in to comment.