From 6f80454361669c49679b8a0deeae343843e83321 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Tue, 16 Dec 2025 10:21:35 +0100 Subject: [PATCH] wasip3 filesystem unlink: Homogenize error returns When attempting to unlink a directory, POSIX specifies the result should be EPERM, but only MacOS implements that behavior. Paper over the differences. Also turn EACCESS into EPERM, to paper over Windows differences. Related to https://github.com/WebAssembly/WASI/pull/852 and https://github.com/WebAssembly/wasi-testsuite/pull/137. POSIX 2008 reference: https://pubs.opengroup.org/onlinepubs/9699919799/functions/unlink.html --- crates/wasi/src/p3/filesystem/host.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/wasi/src/p3/filesystem/host.rs b/crates/wasi/src/p3/filesystem/host.rs index 682fffb75259..57d2f5cb6535 100644 --- a/crates/wasi/src/p3/filesystem/host.rs +++ b/crates/wasi/src/p3/filesystem/host.rs @@ -806,7 +806,23 @@ impl types::HostDescriptorWithStore for WasiFilesystem { path: String, ) -> FilesystemResult<()> { let dir = store.get_dir(&fd)?; - dir.unlink_file_at(path).await?; + dir.unlink_file_at(path).await.map_err(|e| { + match e { + // Linux returns EISDIR when attempting to unlink a + // directory instead of the POSIX-specified EPERM. + crate::filesystem::ErrorCode::IsDirectory => ErrorCode::NotPermitted, + // Windows on the other hand returns EACCESS when + // attempting to unlink a directory. Unfortunately + // filesystem ownership and permissions can also give + // rise to EACCESS, on Windows and elsewhere. However + // give filestem permissions aren't part of WASI, we can + // regain a single behavior if we reduce the precision + // on these errors by mapping all EACCESS errors to + // EPERM, on all platforms. + crate::filesystem::ErrorCode::Access => ErrorCode::NotPermitted, + e => e.into(), + } + })?; Ok(()) }