fix force rm: should suppress error if directory is not found (#11656)

# Description
Fix a breaking change which is introduced by #11621

`rm -f /tmp/aaa` shouldn't return error if `/tmp/aaa/` doesn't exist.

# User-Facing Changes
NaN

# Tests + Formatting
Done
This commit is contained in:
WindSoilder
2024-01-28 23:01:19 +08:00
committed by GitHub
parent 859f7b3dc7
commit 25b62c2ac3
2 changed files with 20 additions and 8 deletions

View File

@ -254,7 +254,6 @@ fn rm(
});
}
// let path = currentdir_path.join(target.item.as_ref());
match nu_engine::glob_from(
&target,
&currentdir_path,
@ -302,13 +301,11 @@ fn rm(
}
}
Err(e) => {
return Err(ShellError::GenericError {
error: e.to_string(),
msg: e.to_string(),
span: Some(target.span),
help: None,
inner: vec![],
})
// glob_from may canonicalize path and return `DirectoryNotFound`
// nushell should suppress the error if `--force` is used.
if !(force && matches!(e, ShellError::DirectoryNotFound { .. })) {
return Err(e);
}
}
};
}