mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
rm: fix dir-type symlink removal on windows
This commit is contained in:
parent
f3d43d775a
commit
41fb27e0a7
1 changed files with 19 additions and 0 deletions
19
src/rm/rm.rs
19
src/rm/rm.rs
|
@ -163,6 +163,8 @@ fn remove(files: Vec<String>, options: Options) -> bool {
|
||||||
Ok(metadata) => {
|
Ok(metadata) => {
|
||||||
if metadata.is_dir() {
|
if metadata.is_dir() {
|
||||||
handle_dir(file, &options)
|
handle_dir(file, &options)
|
||||||
|
} else if is_symlink_dir(&metadata) {
|
||||||
|
remove_dir(file, &options)
|
||||||
} else {
|
} else {
|
||||||
remove_file(file, &options)
|
remove_file(file, &options)
|
||||||
}
|
}
|
||||||
|
@ -305,3 +307,20 @@ fn prompt(msg: &str) -> bool {
|
||||||
_ => false,
|
_ => 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)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue