Skip to content

Commit 4612d65

Browse files
committed
ls: Fix error message for ls /file/directory
1 parent de5e4f5 commit 4612d65

3 files changed

Lines changed: 14 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
@@ -185,6 +185,7 @@ enum LsError {
185185
IOError(#[from] std::io::Error),
186186

187187
#[error("{}", match .1.kind() {
188+
ErrorKind::NotADirectory => translate!("ls-error-not-directory", "path" => .0.quote()),
188189
ErrorKind::NotFound => translate!("ls-error-cannot-access-no-such-file", "path" => .0.quote()),
189190
ErrorKind::PermissionDenied => match .1.raw_os_error().unwrap_or(1) {
190191
1 => translate!("ls-error-cannot-access-operation-not-permitted", "path" => .0.quote()),

tests/by-util/test_ls.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ 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+
65+
scene
66+
.ucmd()
67+
.arg("/sbin/init/dir")
68+
.fails_with_code(2)
69+
.stderr_is("ls: cannot access '/sbin/init/dir': Not a directory\n");
70+
}
71+
6072
#[test]
6173
fn test_invalid_flag() {
6274
new_ucmd!()

0 commit comments

Comments
 (0)