diff options
author | Ron Yorston <rmy@pobox.com> | 2021-02-12 14:07:55 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2021-02-12 14:07:55 +0000 |
commit | 1b61a02b5139a47e2e3ac8be5afca325d7b3cea7 (patch) | |
tree | f9fc7925ed82444ac2ac64fccee4ac7ef9cbd925 | |
parent | e86a3ddd8b60eb0720874f5b9679446d12a1ac41 (diff) | |
download | busybox-w32-1b61a02b5139a47e2e3ac8be5afca325d7b3cea7.tar.gz busybox-w32-1b61a02b5139a47e2e3ac8be5afca325d7b3cea7.tar.bz2 busybox-w32-1b61a02b5139a47e2e3ac8be5afca325d7b3cea7.zip |
win32: allow symlinks to directories to be unlinked
Windows distinguishes between symlinks to directories and files.
A symlink to a directory must be deleted by calling rmdir(2)
rather than unlink(2).
-rw-r--r-- | win32/mingw.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/win32/mingw.c b/win32/mingw.c index 15529ed58..41dba9857 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -1316,9 +1316,21 @@ int fcntl(int fd, int cmd, ...) | |||
1316 | #undef unlink | 1316 | #undef unlink |
1317 | int mingw_unlink(const char *pathname) | 1317 | int mingw_unlink(const char *pathname) |
1318 | { | 1318 | { |
1319 | int ret; | ||
1320 | struct stat st; | ||
1321 | |||
1319 | /* read-only files cannot be removed */ | 1322 | /* read-only files cannot be removed */ |
1320 | chmod(pathname, 0666); | 1323 | chmod(pathname, 0666); |
1321 | return unlink(pathname); | 1324 | |
1325 | ret = unlink(pathname); | ||
1326 | if (ret == -1 && errno == EACCES) { | ||
1327 | /* a symlink to a directory needs to be removed by calling rmdir */ | ||
1328 | if (lstat(pathname, &st) == 0 && S_ISLNK(st.st_mode)) { | ||
1329 | return rmdir(pathname); | ||
1330 | } | ||
1331 | errno = EACCES; | ||
1332 | } | ||
1333 | return ret; | ||
1322 | } | 1334 | } |
1323 | 1335 | ||
1324 | #undef strftime | 1336 | #undef strftime |