1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +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,7 +306,8 @@ fn remove_dir(path: &Path, options: &Options) -> bool {
}; };
if response { if response {
if let Ok(mut read_dir) = fs::read_dir(path) { if let Ok(mut read_dir) = fs::read_dir(path) {
if options.dir && read_dir.next().is_none() { if options.dir || options.recursive {
if read_dir.next().is_none() {
match fs::remove_dir(path) { match fs::remove_dir(path) {
Ok(_) => { Ok(_) => {
if options.verbose { if options.verbose {
@ -323,6 +324,14 @@ fn remove_dir(path: &Path, options: &Options) -> bool {
show_error!("cannot remove '{}': Directory not empty", path.display()); show_error!("cannot remove '{}': Directory not empty", path.display());
return true; return true;
} }
} else {
// 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 { } else {
// GNU's rm shows this message if directory is empty but not readable // GNU's rm shows this message if directory is empty but not readable
show_error!("cannot remove '{}': Directory not empty", path.display()); show_error!("cannot remove '{}': Directory not empty", path.display());

View file

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