Skip to content

Commit 93157b7

Browse files
oech3cakebaker
authored andcommitted
ls: Fix error message for ls file/missing-file
1 parent ad132f3 commit 93157b7

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/uu/ls/locales/en-US.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ ls-error-cannot-open-directory-bad-descriptor = cannot open directory {$path}: B
2222
ls-error-unknown-io-error = unknown io error: {$path}, '{$error}'
2323
ls-error-invalid-block-size = invalid --block-size argument {$size}
2424
ls-error-dired-and-zero-incompatible = --dired and --zero are incompatible
25+
ls-error-not-directory = cannot access {$path}: Not a directory
2526
ls-error-not-listing-already-listed = {$path}: not listing already-listed directory
2627
ls-error-invalid-time-style = invalid --time-style argument {$style}
2728
Possible values are:

src/uu/ls/src/ls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ enum LsError {
6868
IOError(#[from] std::io::Error),
6969

7070
#[error("{}", match .1.kind() {
71+
ErrorKind::NotADirectory => translate!("ls-error-not-directory", "path" => .0.quote()),
7172
ErrorKind::NotFound => translate!("ls-error-cannot-access-no-such-file", "path" => .0.quote()),
7273
ErrorKind::PermissionDenied => match .1.raw_os_error().unwrap_or(1) {
7374
1 => translate!("ls-error-cannot-access-operation-not-permitted", "path" => .0.quote()),

tests/by-util/test_ls.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ const COMMA_ARGS: &[&str] = &["-m", "--format=commas", "--for=commas"];
5757

5858
const COLUMN_ARGS: &[&str] = &["-C", "--format=columns", "--for=columns"];
5959

60+
#[test]
61+
#[cfg(unix)]
62+
fn test_directory_in_file() {
63+
let scene = TestScenario::new(util_name!());
64+
let at = &scene.fixtures;
65+
at.touch("file");
66+
67+
scene
68+
.ucmd()
69+
.arg("file/missing")
70+
.fails_with_code(2)
71+
.stderr_is("ls: cannot access 'file/missing': Not a directory\n");
72+
}
73+
6074
#[test]
6175
fn test_invalid_flag() {
6276
new_ucmd!()

0 commit comments

Comments
 (0)