mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #1033 from shinh/rm-dir-link
rm: Remove symlinks to directories without -r
This commit is contained in:
commit
5f1cb07df8
2 changed files with 21 additions and 1 deletions
10
src/rm/rm.rs
10
src/rm/rm.rs
|
@ -129,7 +129,15 @@ fn remove(files: Vec<String>, force: bool, interactive: InteractiveMode, one_fs:
|
||||||
let filename = &filename[..];
|
let filename = &filename[..];
|
||||||
let file = Path::new(filename);
|
let file = Path::new(filename);
|
||||||
if file.exists() {
|
if file.exists() {
|
||||||
if file.is_dir() {
|
let is_dir = match file.symlink_metadata() {
|
||||||
|
Ok(metadata) => metadata.is_dir(),
|
||||||
|
Err(e) => {
|
||||||
|
had_err = true;
|
||||||
|
show_error!("could not read metadata of '{}': {}", filename, e);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if is_dir {
|
||||||
if recursive && (filename != "/" || !preserve_root) {
|
if recursive && (filename != "/" || !preserve_root) {
|
||||||
if interactive != InteractiveMode::InteractiveAlways {
|
if interactive != InteractiveMode::InteractiveAlways {
|
||||||
if let Err(e) = fs::remove_dir_all(file) {
|
if let Err(e) = fs::remove_dir_all(file) {
|
||||||
|
|
|
@ -136,3 +136,15 @@ fn test_rm_verbose() {
|
||||||
ucmd.arg("-v").arg(file_a).arg(file_b).succeeds()
|
ucmd.arg("-v").arg(file_a).arg(file_b).succeeds()
|
||||||
.stdout_only(format!("removed '{}'\nremoved '{}'\n", file_a, file_b));
|
.stdout_only(format!("removed '{}'\nremoved '{}'\n", file_a, file_b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_rm_dir_symlink() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
let dir = "test_rm_dir_symlink_dir";
|
||||||
|
let link = "test_rm_dir_symlink_link";
|
||||||
|
|
||||||
|
at.mkdir(dir);
|
||||||
|
at.symlink(dir, link);
|
||||||
|
|
||||||
|
ucmd.arg(link).succeeds();
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue