From 89fc5eaae6d0e8b348fdd1933d9df60cf3e5011b Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 22 Feb 2021 23:13:15 +0100 Subject: Do not use `rename()` for symlinks That function would rename the _target_, not the link. Signed-off-by: Johannes Schindelin --- win32/mingw.c | 13 ++++++++----- 1 file 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) #undef rename int mingw_rename(const char *pold, const char *pnew) { + struct mingw_stat st; DWORD attrs; /* - * Try native rename() first to get errno right. + * For non-symlinks, try native rename() first to get errno right. * It is based on MoveFile(), which cannot overwrite existing files. */ - if (!rename(pold, pnew)) - return 0; - if (errno != EEXIST) - return -1; + if (mingw_lstat(pold, &st) || !S_ISLNK(st.st_mode)) { + if (!rename(pold, pnew)) + return 0; + if (errno != EEXIST) + return -1; + } if (MoveFileEx(pold, pnew, MOVEFILE_REPLACE_EXISTING)) return 0; /* TODO: translate more errors */ -- cgit v1.2.3-55-g6feb