From d239d2d5273e1620a6146d8f5076f6532e3569b1 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 17 Oct 2021 13:40:27 +0100 Subject: win32: rmdir(2) shouldn't delete symlinks On Linux rmdir(2) refuses to delete a symlink to a directory on the obvious grounds that a symlink isn't a directory. Windows' rmdir() is less discriminating. Make our implementation of rmdir(2) behave more like Linux. --- win32/mingw.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/win32/mingw.c b/win32/mingw.c index c59d8a7c8..cd121c949 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -1502,6 +1502,7 @@ int fcntl(int fd, int cmd, ...) } #undef unlink +#undef rmdir int mingw_unlink(const char *pathname) { int ret; @@ -1512,6 +1513,7 @@ int mingw_unlink(const char *pathname) ret = unlink(pathname); if (ret == -1 && errno == EACCES) { /* a symlink to a directory needs to be removed by calling rmdir */ + /* (the *real* Windows rmdir, not mingw_rmdir) */ if (is_symlink(pathname)) { return rmdir(pathname); } @@ -1686,9 +1688,14 @@ int mingw_access(const char *name, int mode) return -1; } -#undef rmdir int mingw_rmdir(const char *path) { + /* On Linux rmdir(2) doesn't remove symlinks */ + if (is_symlink(path)) { + errno = ENOTDIR; + return -1; + } + /* read-only directories cannot be removed */ chmod(path, 0666); return rmdir(path); -- cgit v1.2.3-55-g6feb