win32: teach p_open about do_with_retries
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index 6f23734..fd74606 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -438,14 +438,19 @@ int p_symlink(const char *old, const char *new)
return git_futils_fake_symlink(old, new);
}
+GIT_INLINE(int) open_once(const wchar_t *path, int flags, mode_t mode)
+{
+ int ret = _wopen(path, flags, mode);
+
+ return (ret < 0 && last_error_retryable()) ? GIT_RETRY : ret;
+}
+
int p_open(const char *path, int flags, ...)
{
- git_win32_path buf;
+ git_win32_path wpath;
mode_t mode = 0;
- int open_tries;
- int handle;
- if (git_win32_path_from_utf8(buf, path) < 0)
+ if (git_win32_path_from_utf8(wpath, path) < 0)
return -1;
if (flags & O_CREAT) {
@@ -456,23 +461,9 @@ int p_open(const char *path, int flags, ...)
va_end(arg_list);
}
- /* wait up to 50ms if file is locked by another thread or process */
- open_tries = 0;
- while (open_tries < 10) {
- handle = _wopen(buf, flags | STANDARD_OPEN_FLAGS, mode & WIN32_MODE_MASK);
- if (handle != -1) {
- break;
- }
-
- if (errno == EACCES) {
- Sleep(5);
- open_tries++;
- } else {
- break;
- }
- }
-
- return handle;
+ do_with_retries(
+ open_once(wpath, flags | STANDARD_OPEN_FLAGS, mode & WIN32_MODE_MASK),
+ 0);
}
int p_creat(const char *path, mode_t mode)