1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2026-01-19 19:51:09 +00:00

Merge pull request #1315 from rivy/fix.rm

fix ~ rm: fix dir-type symlink removal on windows
This commit is contained in:
Alex Lyon 2019-04-03 15:53:00 -07:00 committed by GitHub
commit dd753e2c78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 16 deletions

View file

@ -163,6 +163,8 @@ fn remove(files: Vec<String>, options: Options) -> bool {
Ok(metadata) => {
if metadata.is_dir() {
handle_dir(file, &options)
} else if is_symlink_dir(&metadata) {
remove_dir(file, &options)
} else {
remove_file(file, &options)
}
@ -305,3 +307,20 @@ fn prompt(msg: &str) -> bool {
_ => false,
}
}
#[cfg(not(windows))]
fn is_symlink_dir(_metadata: &fs::Metadata) -> bool {
false
}
#[cfg(windows)]
use std::os::windows::prelude::MetadataExt;
#[cfg(windows)]
fn is_symlink_dir(metadata: &fs::Metadata) -> bool {
use std::os::raw::c_ulong;
pub type DWORD = c_ulong;
pub const FILE_ATTRIBUTE_DIRECTORY: DWORD = 0x10;
metadata.file_type().is_symlink() && ((metadata.file_attributes() & FILE_ATTRIBUTE_DIRECTORY) != 0)
}