Skip to content

Commit d3f4a32

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 d3f4a32

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

crates/wasi/src/filesystem.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,9 +1131,23 @@ impl Dir {
11311131
if !self.perms.contains(DirPerms::MUTATE) {
11321132
return Err(ErrorCode::NotPermitted);
11331133
}
1134-
self.run_blocking(move |d| d.remove_file_or_symlink(&path))
1135-
.await?;
1136-
Ok(())
1134+
self.run_blocking(move |d| d.remove_file_or_symlink(&path)).await.map_err(|e| {
1135+
match ErrorCode::from(e) {
1136+
// Linux returns EISDIR when attempting to unlink a
1137+
// directory instead of the POSIX-specified EPERM.
1138+
ErrorCode::IsDirectory => ErrorCode::NotPermitted,
1139+
// Windows on the other hand returns EACCESS when
1140+
// attempting to unlink a directory. Unfortunately
1141+
// filesystem ownership and permissions can also give
1142+
// rise to EACCESS, on Windows and elsewhere. However
1143+
// give filestem permissions aren't part of WASI, we can
1144+
// regain a single behavior if we reduce the precision
1145+
// on these errors by mapping all EACCESS errors to
1146+
// EPERM, on all platforms.
1147+
ErrorCode::Access => ErrorCode::NotPermitted,
1148+
e => e,
1149+
}
1150+
})
11371151
}
11381152

11391153
pub(crate) async fn metadata_hash_at(

0 commit comments

Comments
 (0)