mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
fix(ls): When a file doesn't exist, exit early and fails ls
Currently, running $ ls doesntexist will return 0 while it should return 1 Ditto for $ ls doesntexist a
This commit is contained in:
parent
cd97adb39d
commit
8a1628cf89
1 changed files with 15 additions and 3 deletions
|
@ -168,11 +168,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
)
|
||||
.parse(args);
|
||||
|
||||
list(matches);
|
||||
0
|
||||
list(matches)
|
||||
}
|
||||
|
||||
fn list(options: getopts::Matches) {
|
||||
fn list(options: getopts::Matches) -> i32 {
|
||||
let locs: Vec<String> = if options.free.is_empty() {
|
||||
vec![String::from(".")]
|
||||
} else {
|
||||
|
@ -181,8 +180,16 @@ fn list(options: getopts::Matches) {
|
|||
|
||||
let mut files = Vec::<PathBuf>::new();
|
||||
let mut dirs = Vec::<PathBuf>::new();
|
||||
let mut has_failed = false;
|
||||
for loc in locs {
|
||||
let p = PathBuf::from(&loc);
|
||||
if !p.exists() {
|
||||
show_error!("'{}': {}", &loc, "No such file or directory");
|
||||
// We found an error, the return code of ls should not be 0
|
||||
// And no need to continue the execution
|
||||
has_failed = true;
|
||||
continue;
|
||||
}
|
||||
let mut dir = false;
|
||||
|
||||
if p.is_dir() && !options.opt_present("d") {
|
||||
|
@ -211,6 +218,11 @@ fn list(options: getopts::Matches) {
|
|||
}
|
||||
enter_directory(&dir, &options);
|
||||
}
|
||||
if has_failed {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(unix, target_os = "redox"))]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue