win32: teach p_open about do_with_retries

This commit is contained in:
Edward Thomson 2017-04-01 13:25:14 +01:00
parent a0f67e4a26
commit fbc6910f6b

View File

@ -438,14 +438,19 @@ int p_symlink(const char *old, const char *new)
return git_futils_fake_symlink(old, 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, ...) int p_open(const char *path, int flags, ...)
{ {
git_win32_path buf; git_win32_path wpath;
mode_t mode = 0; 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; return -1;
if (flags & O_CREAT) { if (flags & O_CREAT) {
@ -456,23 +461,9 @@ int p_open(const char *path, int flags, ...)
va_end(arg_list); va_end(arg_list);
} }
/* wait up to 50ms if file is locked by another thread or process */ do_with_retries(
open_tries = 0; open_once(wpath, flags | STANDARD_OPEN_FLAGS, mode & WIN32_MODE_MASK),
while (open_tries < 10) { 0);
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;
} }
int p_creat(const char *path, mode_t mode) int p_creat(const char *path, mode_t mode)