aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-04-15 13:50:13 -0700
committerJunio C Hamano <gitster@pobox.com>2025-04-15 13:50:13 -0700
commit139d70351163d58da9abd98bed221624450f2225 (patch)
treeb1323c4ada6db87c3790922da0aa4868250cd05d
parent485f5f863615e670fd97ae40af744e14072cfe18 (diff)
parent3262a53c123844b3b9140f4e35b86f1444555aad (diff)
downloadgit-139d70351163d58da9abd98bed221624450f2225.tar.gz
Merge branch 'ps/reftable-windows-unlink-fix'
Portability fix. * ps/reftable-windows-unlink-fix: reftable: ignore file-in-use errors when unlink(3p) fails on Windows
-rw-r--r--compat/mingw-posix.h8
-rw-r--r--compat/mingw.c5
-rw-r--r--reftable/system.h1
3 files changed, 11 insertions, 3 deletions
diff --git a/compat/mingw-posix.h b/compat/mingw-posix.h
index 8dddfa818d..88e0cf9292 100644
--- a/compat/mingw-posix.h
+++ b/compat/mingw-posix.h
@@ -201,8 +201,12 @@ int uname(struct utsname *buf);
* replacements of existing functions
*/
-int mingw_unlink(const char *pathname);
-#define unlink mingw_unlink
+int mingw_unlink(const char *pathname, int handle_in_use_error);
+#ifdef MINGW_DONT_HANDLE_IN_USE_ERROR
+# define unlink(path) mingw_unlink(path, 0)
+#else
+# define unlink(path) mingw_unlink(path, 1)
+#endif
int mingw_rmdir(const char *path);
#define rmdir mingw_rmdir
diff --git a/compat/mingw.c b/compat/mingw.c
index 305a999f1f..6ea2e7a35b 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -302,7 +302,7 @@ static wchar_t *normalize_ntpath(wchar_t *wbuf)
return wbuf;
}
-int mingw_unlink(const char *pathname)
+int mingw_unlink(const char *pathname, int handle_in_use_error)
{
int ret, tries = 0;
wchar_t wpathname[MAX_PATH];
@@ -317,6 +317,9 @@ int mingw_unlink(const char *pathname)
while ((ret = _wunlink(wpathname)) == -1 && tries < ARRAY_SIZE(delay)) {
if (!is_file_in_use_error(GetLastError()))
break;
+ if (!handle_in_use_error)
+ return ret;
+
/*
* We assume that some other process had the source or
* destination file open at the wrong moment and retry.
diff --git a/reftable/system.h b/reftable/system.h
index 10055fbff2..072d9daea0 100644
--- a/reftable/system.h
+++ b/reftable/system.h
@@ -11,6 +11,7 @@ https://developers.google.com/open-source/licenses/bsd
/* This header glues the reftable library to the rest of Git */
+#define MINGW_DONT_HANDLE_IN_USE_ERROR
#include "compat/posix.h"
#include "compat/zlib-compat.h"