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

rm: make -d/-r obligatory for removing symlink_dir (windows)

This commit is contained in:
Jan Scheer 2021-03-23 19:12:10 +01:00
parent 58b9372dbe
commit bdf603a65e
2 changed files with 23 additions and 11 deletions

View file

@ -306,21 +306,30 @@ fn remove_dir(path: &Path, options: &Options) -> bool {
};
if response {
if let Ok(mut read_dir) = fs::read_dir(path) {
if options.dir && read_dir.next().is_none() {
match fs::remove_dir(path) {
Ok(_) => {
if options.verbose {
println!("removed directory '{}'", path.display());
if options.dir || options.recursive {
if read_dir.next().is_none() {
match fs::remove_dir(path) {
Ok(_) => {
if options.verbose {
println!("removed directory '{}'", path.display());
}
}
Err(e) => {
show_error!("cannot remove '{}': {}", path.display(), e);
return true;
}
}
Err(e) => {
show_error!("cannot remove '{}': {}", path.display(), e);
return true;
}
} else {
// directory can be read but is not empty
show_error!("cannot remove '{}': Directory not empty", path.display());
return true;
}
} else {
// directory can be read but is not empty
show_error!("cannot remove '{}': Directory not empty", path.display());
// called to remove a symlink_dir (windows) without "-r"/"-R" or "-d"
show_error!(
"could not remove directory '{}' (did you mean to pass '-r' or '-R'?)",
path.display()
);
return true;
}
} else {

View file

@ -194,7 +194,10 @@ fn test_rm_dir_symlink() {
at.mkdir(dir);
at.symlink_dir(dir, link);
#[cfg(not(windows))]
ucmd.arg(link).succeeds();
#[cfg(windows)]
ucmd.arg("-r").arg(link).succeeds();
}
#[test]