Fix remove() directory on Windows

This commit is contained in:
Justine Tunney 2024-07-28 15:02:11 -07:00
parent e18fe1e112
commit 18964e5d76
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
3 changed files with 18 additions and 6 deletions

View file

@ -53,12 +53,13 @@ int unlinkat(int dirfd, const char *path, int flags) {
// POSIX.1 says unlink(directory) raises EPERM but on Linux
// it always raises EISDIR, which is so much less ambiguous
if (!IsLinux() && rc == -1 && !flags && errno == EPERM) {
int e = errno;
if (!IsLinux() && rc == -1 && !flags && (e == EPERM || e == EACCES)) {
struct stat st;
if (!fstatat(dirfd, path, &st, 0) && S_ISDIR(st.st_mode)) {
errno = EISDIR;
} else {
errno = EPERM;
errno = e;
}
}