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:
Sylvestre Ledru
2026-04-04 22:21:07 +02:00
committed by GitHub
parent 79209719f9
commit 8c100daa66
3 changed files with 31 additions and 1 deletions
+3
View File
@@ -219,6 +219,9 @@ nofield
dtolnay
Swatinem
preopened
dotdot
# * clippy
uninlined
nonminimal
+13 -1
View File
@@ -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,
+15
View File
@@ -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();
}