Skip to content

Specify unlink-file-at in terms of POSIX.#852

Merged
badeend merged 1 commit intoWebAssembly:mainfrom
wingo:unlink-errors
Feb 26, 2026
Merged

Specify unlink-file-at in terms of POSIX.#852
badeend merged 1 commit intoWebAssembly:mainfrom
wingo:unlink-errors

Conversation

@wingo
Copy link
Contributor

@wingo wingo commented Dec 16, 2025

Unfortunately only MacOS has the POSIX behavior of returning EPERM when unlinking a directory; Linux returns EISDIR, and Windows returns EACCESS. Because EACCESS may arise for other reasons but which are outside the purview of WASI, we map all EACCESS to EPERM.

@wingo wingo requested a review from a team as a code owner December 16, 2025 09:29
@github-actions github-actions bot added the P-filesystem Proposal: wasi-filesystem label Dec 16, 2025
wingo added a commit to wingo/wasmtime that referenced this pull request Dec 16, 2025
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
wingo added a commit to wingo/wasi-testsuite that referenced this pull request Dec 16, 2025
wingo added a commit to wingo/wasmtime that referenced this pull request Dec 16, 2025
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
wingo added a commit to wingo/wasmtime that referenced this pull request Dec 16, 2025
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
wingo added a commit to wingo/wasmtime that referenced this pull request Dec 16, 2025
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
@badeend
Copy link
Member

badeend commented Dec 16, 2025

If all major OS flavors return something different, then clearly POSIX is not the authoritative source here. Additionally, the page you referenced includes the footnote:

The standard developers reviewed TR 24715-2006 and noted that LSB-conforming implementations may return [EISDIR] instead of [EPERM] when unlinking a directory.

I personally don't see anything wrong with Linux' behavior of returning EISDIR; it is more to-the-point and precisely describes why it failed, instead of a catch-all EPERM.

@wingo
Copy link
Contributor Author

wingo commented Dec 17, 2025

Ah, thank you for that footnote, I missed it! And I do like Linux's return code! But if we want one semantics, EISDIR isn't it, as we can't translate results from other platforms without races.

Another option would be to relax WASI to allow but not require is-directory.

@badeend
Copy link
Member

badeend commented Dec 23, 2025

if we want one semantics

As a general piece of advice: I'd keep away from trying to synthesize a single semantic model for "filesystems" in general. Each OS works differently, and even within a single OS, different filesystem implementations (NTFS, FAT32, EXT4, ..) can produce different results.

Another option would be to relax WASI to allow but not require is-directory

That sounds like a good solution to me. 👍

@vados-cosmonic
Copy link
Contributor

vados-cosmonic commented Feb 6, 2026

Hey @wingo thanks for this contribution and the discussion -- would you be open to making the note even more specific?

If we're going to note that there are some discrepancies we might as well be specific about which platforms do what to prevent confusion down the line, until this is fixed/not the case.

Another option would be to relax WASI to allow but not require is-directory.

Are you up for contributing this? This sounds like the right solution (regardless of whether this PR is merged in the meantime). If we go in this direction then the note should actually be more specific (looks like in any case it should be more specific), and it will be up to implementers to follow the semantics (or choose to return error-code::is-directory)

@wingo
Copy link
Contributor Author

wingo commented Feb 12, 2026

Thanks for review, updated the text to instead allow is-directory and access in addition to not-permitted. WDYT @badeend @vados-cosmonic ?

@vados-cosmonic
Copy link
Contributor

This looks great to me! If you want to resolve the conflict that would be great, let's get this in ASAP as long as @badeend doesn't have any objections

@badeend
Copy link
Member

badeend commented Feb 12, 2026

LGTM 👍

@wingo wingo requested a review from a team as a code owner February 26, 2026 09:30
@wingo
Copy link
Contributor Author

wingo commented Feb 26, 2026

rebased, ptal !

Copy link
Contributor

@vados-cosmonic vados-cosmonic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@badeend badeend added this pull request to the merge queue Feb 26, 2026
Merged via the queue into WebAssembly:main with commit b16a206 Feb 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P-filesystem Proposal: wasi-filesystem P-sockets Proposal: wasi-sockets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants