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

Merge pull request #5278 from sylvestre/ls-no-read

ls -l: show an error when symlink not readable
This commit is contained in:
Daniel Hofstetter 2023-09-16 15:15:36 +02:00 committed by GitHub
commit fe4def8ac0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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");
}