mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
parent
dc63133f14
commit
9f1deb2df6
2 changed files with 25 additions and 0 deletions
|
@ -20,6 +20,11 @@ static OPT_VERBOSE: &str = "verbose";
|
||||||
|
|
||||||
static ARG_DIRS: &str = "dirs";
|
static ARG_DIRS: &str = "dirs";
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
static ENOTDIR: i32 = 20;
|
||||||
|
#[cfg(windows)]
|
||||||
|
static ENOTDIR: i32 = 267;
|
||||||
|
|
||||||
fn get_usage() -> String {
|
fn get_usage() -> String {
|
||||||
format!("{0} [OPTION]... DIRECTORY...", executable!())
|
format!("{0} [OPTION]... DIRECTORY...", executable!())
|
||||||
}
|
}
|
||||||
|
@ -105,6 +110,10 @@ fn remove(dirs: Vec<String>, ignore: bool, parents: bool, verbose: bool) -> Resu
|
||||||
fn remove_dir(path: &Path, ignore: bool, verbose: bool) -> Result<(), i32> {
|
fn remove_dir(path: &Path, ignore: bool, verbose: bool) -> Result<(), i32> {
|
||||||
let mut read_dir = match fs::read_dir(path) {
|
let mut read_dir = match fs::read_dir(path) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
|
Err(e) if e.raw_os_error() == Some(ENOTDIR) => {
|
||||||
|
show_error!("failed to remove '{}': Not a directory", path.display());
|
||||||
|
return Err(1);
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
show_error!("reading directory '{}': {}", path.display(), e);
|
show_error!("reading directory '{}': {}", path.display(), e);
|
||||||
return Err(1);
|
return Err(1);
|
||||||
|
|
|
@ -108,3 +108,19 @@ fn test_rmdir_ignore_nonempty_directory_with_parents() {
|
||||||
|
|
||||||
assert!(at.dir_exists(dir));
|
assert!(at.dir_exists(dir));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_rmdir_remove_symlink_match_gnu_error() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
|
||||||
|
let file = "file";
|
||||||
|
let fl = "fl";
|
||||||
|
at.touch(file);
|
||||||
|
assert!(at.file_exists(file));
|
||||||
|
at.symlink_file(file, fl);
|
||||||
|
assert!(at.file_exists(fl));
|
||||||
|
|
||||||
|
ucmd.arg("fl/")
|
||||||
|
.fails()
|
||||||
|
.stderr_is("rmdir: failed to remove 'fl/': Not a directory");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue