1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

ls -l: show an error when symlink not readable

switching to match and handle the error

Will help with tests/ls/stat-failed.sh
This commit is contained in:
Sylvestre Ledru 2023-09-15 22:34:17 +02:00
parent 97aa8ae5db
commit 37ee889003
2 changed files with 71 additions and 43 deletions

View file

@ -2908,7 +2908,8 @@ fn display_file_name(
&& path.file_type(out).unwrap().is_symlink()
&& !path.must_dereference
{
if let Ok(target) = path.p_buf.read_link() {
match path.p_buf.read_link() {
Ok(target) => {
name.push_str(" -> ");
// We might as well color the symlink output after the arrow.
@ -2959,6 +2960,14 @@ fn display_file_name(
name.push_str(&escape_name(target.as_os_str(), &config.quoting_style));
}
}
Err(err) => {
show!(LsError::IOErrorContext(
err,
path.p_buf.to_path_buf(),
false
));
}
}
}
// Prepend the security context to the `name` and adjust `width` in order

View file

@ -3503,3 +3503,22 @@ fn test_invalid_utf8() {
at.touch(filename);
ucmd.succeeds();
}
#[cfg(all(unix, feature = "chmod"))]
#[test]
fn test_ls_perm_io_errors() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.mkdir("d");
at.symlink_file("/", "d/s");
scene.ccmd("chmod").arg("600").arg("d").succeeds();
scene
.ucmd()
.arg("-l")
.arg("d")
.fails()
.code_is(1)
.stderr_contains("Permission denied");
}