aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2021-02-22 23:13:15 +0100
committerRon Yorston <rmy@pobox.com>2021-03-01 09:35:31 +0000
commit89fc5eaae6d0e8b348fdd1933d9df60cf3e5011b (patch)
tree69b3343fb8d333ef1a569992b48a37a7ec4895d2
parent3c44f5cae158ff4ffd03a4c319777ae88a60bcb9 (diff)
downloadbusybox-w32-89fc5eaae6d0e8b348fdd1933d9df60cf3e5011b.tar.gz
busybox-w32-89fc5eaae6d0e8b348fdd1933d9df60cf3e5011b.tar.bz2
busybox-w32-89fc5eaae6d0e8b348fdd1933d9df60cf3e5011b.zip
Do not use `rename()` for symlinks
That function would rename the _target_, not the link. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
-rw-r--r--win32/mingw.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index 50ab92f0d..443566a60 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -829,16 +829,19 @@ char *mingw_getcwd(char *pointer, int len)
829#undef rename 829#undef rename
830int mingw_rename(const char *pold, const char *pnew) 830int mingw_rename(const char *pold, const char *pnew)
831{ 831{
832 struct mingw_stat st;
832 DWORD attrs; 833 DWORD attrs;
833 834
834 /* 835 /*
835 * Try native rename() first to get errno right. 836 * For non-symlinks, try native rename() first to get errno right.
836 * It is based on MoveFile(), which cannot overwrite existing files. 837 * It is based on MoveFile(), which cannot overwrite existing files.
837 */ 838 */
838 if (!rename(pold, pnew)) 839 if (mingw_lstat(pold, &st) || !S_ISLNK(st.st_mode)) {
839 return 0; 840 if (!rename(pold, pnew))
840 if (errno != EEXIST) 841 return 0;
841 return -1; 842 if (errno != EEXIST)
843 return -1;
844 }
842 if (MoveFileEx(pold, pnew, MOVEFILE_REPLACE_EXISTING)) 845 if (MoveFileEx(pold, pnew, MOVEFILE_REPLACE_EXISTING))
843 return 0; 846 return 0;
844 /* TODO: translate more errors */ 847 /* TODO: translate more errors */