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
This commit is contained in:
Junio C Hamano
2025-04-15 13:50:13 -07:00
3 changed files with 11 additions and 3 deletions

View File

@@ -201,8 +201,12 @@ int uname(struct utsname *buf);
* replacements of existing functions * replacements of existing functions
*/ */
int mingw_unlink(const char *pathname); int mingw_unlink(const char *pathname, int handle_in_use_error);
#define unlink mingw_unlink #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); int mingw_rmdir(const char *path);
#define rmdir mingw_rmdir #define rmdir mingw_rmdir

View File

@@ -302,7 +302,7 @@ static wchar_t *normalize_ntpath(wchar_t *wbuf)
return wbuf; return wbuf;
} }
int mingw_unlink(const char *pathname) int mingw_unlink(const char *pathname, int handle_in_use_error)
{ {
int ret, tries = 0; int ret, tries = 0;
wchar_t wpathname[MAX_PATH]; wchar_t wpathname[MAX_PATH];
@@ -317,6 +317,9 @@ int mingw_unlink(const char *pathname)
while ((ret = _wunlink(wpathname)) == -1 && tries < ARRAY_SIZE(delay)) { while ((ret = _wunlink(wpathname)) == -1 && tries < ARRAY_SIZE(delay)) {
if (!is_file_in_use_error(GetLastError())) if (!is_file_in_use_error(GetLastError()))
break; break;
if (!handle_in_use_error)
return ret;
/* /*
* We assume that some other process had the source or * We assume that some other process had the source or
* destination file open at the wrong moment and retry. * destination file open at the wrong moment and retry.

View File

@@ -11,6 +11,7 @@ https://developers.google.com/open-source/licenses/bsd
/* This header glues the reftable library to the rest of Git */ /* This header glues the reftable library to the rest of Git */
#define MINGW_DONT_HANDLE_IN_USE_ERROR
#include "compat/posix.h" #include "compat/posix.h"
#include "compat/zlib-compat.h" #include "compat/zlib-compat.h"