mirror of
https://github.com/uutils/coreutils.git
synced 2026-05-06 07:26:38 -04:00
ls: fall back to "." metadata for ".." on WASI (#11633)
* ls: fall back to "." metadata for ".." on WASI On WASI the sandbox blocks access to the parent directory at the preopened root, causing ls -a to show an error and display ".." with question marks. Fall back to the current directory metadata so the entry appears with valid information.
This commit is contained in:
@@ -219,6 +219,9 @@ nofield
|
||||
dtolnay
|
||||
Swatinem
|
||||
|
||||
preopened
|
||||
dotdot
|
||||
|
||||
# * clippy
|
||||
uninlined
|
||||
nonminimal
|
||||
|
||||
+13
-1
@@ -1265,7 +1265,19 @@ fn depth_first_list(
|
||||
false,
|
||||
),
|
||||
PathData::new(
|
||||
path_data.path().join("..").into(),
|
||||
// On WASI the sandbox may block access to ".." at the
|
||||
// preopened root. Fall back to "." so the entry still
|
||||
// appears with valid metadata instead of an error.
|
||||
{
|
||||
let dotdot = path_data.path().join("..");
|
||||
#[cfg(target_os = "wasi")]
|
||||
let dotdot = if dotdot.metadata().is_err() {
|
||||
path_data.path().into()
|
||||
} else {
|
||||
dotdot
|
||||
};
|
||||
dotdot.into()
|
||||
},
|
||||
None,
|
||||
Some(OsStr::new("..").into()),
|
||||
config,
|
||||
|
||||
@@ -7133,3 +7133,18 @@ fn test_ls_non_utf8_hidden() {
|
||||
|
||||
scene.ucmd().succeeds().stdout_does_not_contain(".hidden");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "wasi")]
|
||||
fn test_ls_a_dotdot_no_error_on_wasi() {
|
||||
// On WASI the sandbox may block access to ".." at the preopened root.
|
||||
// ls -a should still succeed and show ".." without an error message.
|
||||
let scene = TestScenario::new(util_name!());
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-a")
|
||||
.arg("-1")
|
||||
.succeeds()
|
||||
.stdout_contains("..")
|
||||
.no_stderr();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user