diff options
author | Ron Yorston <rmy@pobox.com> | 2021-10-17 13:40:27 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2021-10-17 13:52:54 +0100 |
commit | d239d2d5273e1620a6146d8f5076f6532e3569b1 (patch) | |
tree | fb406186e3ad29c6922d3373d3823927a9824a8b | |
parent | 1afcef2f5a089648430a13b2a55ba1428c8d49c0 (diff) | |
download | busybox-w32-FRP-4487-gd239d2d52.tar.gz busybox-w32-FRP-4487-gd239d2d52.tar.bz2 busybox-w32-FRP-4487-gd239d2d52.zip |
win32: rmdir(2) shouldn't delete symlinksFRP-4487-gd239d2d52
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.
-rw-r--r-- | win32/mingw.c | 9 |
1 files changed, 8 insertions, 1 deletions
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, ...) | |||
1502 | } | 1502 | } |
1503 | 1503 | ||
1504 | #undef unlink | 1504 | #undef unlink |
1505 | #undef rmdir | ||
1505 | int mingw_unlink(const char *pathname) | 1506 | int mingw_unlink(const char *pathname) |
1506 | { | 1507 | { |
1507 | int ret; | 1508 | int ret; |
@@ -1512,6 +1513,7 @@ int mingw_unlink(const char *pathname) | |||
1512 | ret = unlink(pathname); | 1513 | ret = unlink(pathname); |
1513 | if (ret == -1 && errno == EACCES) { | 1514 | if (ret == -1 && errno == EACCES) { |
1514 | /* a symlink to a directory needs to be removed by calling rmdir */ | 1515 | /* a symlink to a directory needs to be removed by calling rmdir */ |
1516 | /* (the *real* Windows rmdir, not mingw_rmdir) */ | ||
1515 | if (is_symlink(pathname)) { | 1517 | if (is_symlink(pathname)) { |
1516 | return rmdir(pathname); | 1518 | return rmdir(pathname); |
1517 | } | 1519 | } |
@@ -1686,9 +1688,14 @@ int mingw_access(const char *name, int mode) | |||
1686 | return -1; | 1688 | return -1; |
1687 | } | 1689 | } |
1688 | 1690 | ||
1689 | #undef rmdir | ||
1690 | int mingw_rmdir(const char *path) | 1691 | int mingw_rmdir(const char *path) |
1691 | { | 1692 | { |
1693 | /* On Linux rmdir(2) doesn't remove symlinks */ | ||
1694 | if (is_symlink(path)) { | ||
1695 | errno = ENOTDIR; | ||
1696 | return -1; | ||
1697 | } | ||
1698 | |||
1692 | /* read-only directories cannot be removed */ | 1699 | /* read-only directories cannot be removed */ |
1693 | chmod(path, 0666); | 1700 | chmod(path, 0666); |
1694 | return rmdir(path); | 1701 | return rmdir(path); |