1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

rm: fix dir-type symlink removal on windows

This commit is contained in:
Roy Ivy III 2018-11-14 19:54:15 -06:00 committed by Roy Ivy III
parent f3d43d775a
commit 41fb27e0a7

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)
}