Skip to content

Commit fbc6910

Browse files
committed
win32: teach p_open about do_with_retries
1 parent a0f67e4 commit fbc6910

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

src/win32/posix_w32.c

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -438,14 +438,19 @@ int p_symlink(const char *old, const char *new)
438438
return git_futils_fake_symlink(old, new);
439439
}
440440

441+
GIT_INLINE(int) open_once(const wchar_t *path, int flags, mode_t mode)
442+
{
443+
int ret = _wopen(path, flags, mode);
444+
445+
return (ret < 0 && last_error_retryable()) ? GIT_RETRY : ret;
446+
}
447+
441448
int p_open(const char *path, int flags, ...)
442449
{
443-
git_win32_path buf;
450+
git_win32_path wpath;
444451
mode_t mode = 0;
445-
int open_tries;
446-
int handle;
447452

448-
if (git_win32_path_from_utf8(buf, path) < 0)
453+
if (git_win32_path_from_utf8(wpath, path) < 0)
449454
return -1;
450455

451456
if (flags & O_CREAT) {
@@ -456,23 +461,9 @@ int p_open(const char *path, int flags, ...)
456461
va_end(arg_list);
457462
}
458463

459-
/* wait up to 50ms if file is locked by another thread or process */
460-
open_tries = 0;
461-
while (open_tries < 10) {
462-
handle = _wopen(buf, flags | STANDARD_OPEN_FLAGS, mode & WIN32_MODE_MASK);
463-
if (handle != -1) {
464-
break;
465-
}
466-
467-
if (errno == EACCES) {
468-
Sleep(5);
469-
open_tries++;
470-
} else {
471-
break;
472-
}
473-
}
474-
475-
return handle;
464+
do_with_retries(
465+
open_once(wpath, flags | STANDARD_OPEN_FLAGS, mode & WIN32_MODE_MASK),
466+
0);
476467
}
477468

478469
int p_creat(const char *path, mode_t mode)

0 commit comments

Comments
 (0)