Skip to content

Commit 1c1bdbb

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 1c1bdbb

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

crates/wasi/src/filesystem.rs

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

11391155
pub(crate) async fn metadata_hash_at(

0 commit comments

Comments
 (0)