Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/uu/ls/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ls-error-cannot-access-operation-not-permitted = cannot access {$path}: Operatio
ls-error-cannot-open-directory-permission-denied = cannot open directory {$path}: Permission denied
ls-error-cannot-access-permission-denied = cannot access {$path}: Permission denied
ls-error-cannot-open-directory-bad-descriptor = cannot open directory {$path}: Bad file descriptor
ls-error-unknown-io-error = unknown io error: {$path}, '{$error}'
ls-error-cannot-access = cannot access {$path}: {$error}
ls-error-invalid-block-size = invalid --block-size argument {$size}
ls-error-dired-and-zero-incompatible = --dired and --zero are incompatible
ls-error-not-directory = cannot access {$path}: Not a directory
Expand Down
2 changes: 1 addition & 1 deletion src/uu/ls/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ls-error-cannot-access-operation-not-permitted = impossible d'accéder à {$path
ls-error-cannot-open-directory-permission-denied = impossible d'ouvrir le répertoire {$path} : Permission refusée
ls-error-cannot-access-permission-denied = impossible d'accéder à {$path} : Permission refusée
ls-error-cannot-open-directory-bad-descriptor = impossible d'ouvrir le répertoire {$path} : Mauvais descripteur de fichier
ls-error-unknown-io-error = erreur d'E/S inconnue : {$path}, '{$error}'
ls-error-cannot-access = impossible d'accéder à {$path} : {$error}
ls-error-invalid-block-size = argument --block-size invalide {$size}
ls-error-dired-and-zero-incompatible = --dired et --zero sont incompatibles
ls-error-not-listing-already-listed = {$path} : ne liste pas un répertoire déjà listé
Expand Down
2 changes: 1 addition & 1 deletion src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ enum LsError {
_ => if 9 == .1.raw_os_error().unwrap_or(1) {
translate!("ls-error-cannot-open-directory-bad-descriptor", "path" => .0.quote())
} else {
translate!("ls-error-unknown-io-error", "path" => .0.quote(), "error" => format!("{:?}", .1))
translate!("ls-error-cannot-access", "path" => .0.quote(), "error" => strip_errno(.1))
},
})]
IOErrorContext(PathBuf, std::io::Error, bool),
Expand Down
27 changes: 27 additions & 0 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,33 @@ fn test_directory_in_file() {
.stderr_is("ls: cannot access 'file/missing': Not a directory\n");
}

#[test]
fn test_name_too_long() {
let name = "a".repeat(300);
let result = new_ucmd!().arg(&name).fails_with_code(2);
#[cfg(unix)]
result.stderr_is(format!("ls: cannot access '{name}': File name too long\n"));
#[cfg(not(unix))]
result
.stderr_contains(format!("ls: cannot access '{name}': "))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on unix, could we check the full message with stderr_is("... File name too long\n")? the prefix check is a bit weak

.stderr_does_not_contain("os error");
}

#[test]
#[cfg(windows)]
fn test_invalid_filename_windows() {
// `*` and `<` cannot appear in a Windows file name, so the lookup fails
// with ERROR_INVALID_NAME rather than "not found"
for name in ["a*", "a<b"] {
new_ucmd!()
.arg(name)
.fails_with_code(2)
.stderr_contains(format!("ls: cannot access '{name}': "))
.stderr_does_not_contain("unknown io error")
.stderr_does_not_contain("os error");
}
}

#[test]
fn test_invalid_flag() {
new_ucmd!()
Expand Down
Loading