-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Windows: fix POSIX compliance of Sys.remove and Unix.unlink
This patch fixes two issues: - Sys.remove and Unix.unlink would not remove symlinks to directories; - Sys.remove and Unix.unlink would return EACCES error instead of EPERM when trying to delete directories. This patch fixes them both and brings the Windows implementation up to POSIX compliance, which requires the two behaviours above. On Windows, calling _unlink on a path may fail with EACCES if [1]: 1. the path specifies a read-only file; 2. the path specifies a directory. Symlinks to directories "count" as directories themselves, so _unlink will fail on them. However, POSIX unlink(2) specifies [2] that it will gladly unlink symlinks to directories. POSIX unlink also forbids deletion of directories. To emulate that behaviour, we wrap the unlink call. If it fails with EACCES, we have to check whether the path is a symlink. If so, we call rmdir on it. If the path is a directory, we return EPERM. If not, we return the original error. [1]: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/unlink-wunlink?view=msvc-160 [2]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/unlink.html
- Loading branch information
Showing
5 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters