Skip to content

Commit 3b8ab4a

Browse files
committed
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 WebAssembly/WASI#852 and WebAssembly/wasi-testsuite#137. POSIX 2008 reference: https://pubs.opengroup.org/onlinepubs/9699919799/functions/unlink.html
1 parent 87ed3b6 commit 3b8ab4a

File tree

1 file changed

+17
-2
lines changed
  • crates/wasi/src/p3/filesystem

1 file changed

+17
-2
lines changed

crates/wasi/src/p3/filesystem/host.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,8 +806,23 @@ impl types::HostDescriptorWithStore for WasiFilesystem {
806806
path: String,
807807
) -> FilesystemResult<()> {
808808
let dir = store.get_dir(&fd)?;
809-
dir.unlink_file_at(path).await?;
810-
Ok(())
809+
dir.unlink_file_at(path).await.map_err(|e| {
810+
match e {
811+
// Linux returns EISDIR when attempting to unlink a
812+
// directory instead of the POSIX-specified EPERM.
813+
ErrorCode::IsDirectory => ErrorCode::NotPermitted,
814+
// Windows on the other hand returns EACCESS when
815+
// attempting to unlink a directory. Unfortunately
816+
// filesystem ownership and permissions can also give
817+
// rise to EACCESS, on Windows and elsewhere. However
818+
// give filestem permissions aren't part of WASI, we can
819+
// regain a single behavior if we reduce the precision
820+
// on these errors by mapping all EACCESS errors to
821+
// EPERM, on all platforms.
822+
ErrorCode::Access => ErrorCode::NotPermitted,
823+
e => e,
824+
}
825+
})
811826
}
812827

813828
async fn is_same_object<U>(

0 commit comments

Comments
 (0)