mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-18 02:18:07 +00:00
Add retries to win32 p_unlink and p_open.
This commit is contained in:
parent
4d384d6bbe
commit
32269b15e2
@ -93,17 +93,31 @@ int p_unlink(const char *path)
|
|||||||
{
|
{
|
||||||
git_win32_path buf;
|
git_win32_path buf;
|
||||||
int error;
|
int error;
|
||||||
|
int unlink_tries;
|
||||||
|
|
||||||
if (git_win32_path_from_utf8(buf, path) < 0)
|
if (git_win32_path_from_utf8(buf, path) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
error = _wunlink(buf);
|
/* wait up to 50ms if file is locked by another thread or process */
|
||||||
|
unlink_tries = 0;
|
||||||
/* If the file could not be deleted because it was
|
while (unlink_tries < 10) {
|
||||||
* read-only, clear the bit and try again */
|
|
||||||
if (error == -1 && errno == EACCES) {
|
|
||||||
_wchmod(buf, 0666);
|
|
||||||
error = _wunlink(buf);
|
error = _wunlink(buf);
|
||||||
|
|
||||||
|
/* If the file could not be deleted because it was
|
||||||
|
* read-only, clear the bit and try again */
|
||||||
|
if (error == -1 && errno == EACCES) {
|
||||||
|
_wchmod(buf, 0666);
|
||||||
|
error = _wunlink(buf);
|
||||||
|
|
||||||
|
if (error == -1 && errno == EACCES) {
|
||||||
|
Sleep(5);
|
||||||
|
unlink_tries++;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
@ -284,6 +298,8 @@ int p_open(const char *path, int flags, ...)
|
|||||||
{
|
{
|
||||||
git_win32_path buf;
|
git_win32_path buf;
|
||||||
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(buf, path) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -296,7 +312,23 @@ int p_open(const char *path, int flags, ...)
|
|||||||
va_end(arg_list);
|
va_end(arg_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _wopen(buf, flags | STANDARD_OPEN_FLAGS, mode & WIN32_MODE_MASK);
|
/* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
int p_creat(const char *path, mode_t mode)
|
int p_creat(const char *path, mode_t mode)
|
||||||
|
Loading…
Reference in New Issue
Block a user