Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
8a4e1513
Commit
8a4e1513
authored
Apr 01, 2017
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
win32: make p_rename use do_with_retries
parent
cc8d9a29
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
36 deletions
+21
-36
src/win32/posix_w32.c
+21
-36
No files found.
src/win32/posix_w32.c
View file @
8a4e1513
...
...
@@ -749,62 +749,47 @@ int p_access(const char* path, mode_t mode)
return
_waccess
(
buf
,
mode
&
WIN32_MODE_MASK
);
}
static
int
ensure_writable
(
wchar_t
*
f
path
)
static
int
ensure_writable
(
wchar_t
*
path
)
{
DWORD
attrs
;
attrs
=
GetFileAttributesW
(
fpath
);
if
(
attrs
==
INVALID_FILE_ATTRIBUTES
)
{
if
(
GetLastError
()
==
ERROR_FILE_NOT_FOUND
)
if
((
attrs
=
GetFileAttributesW
(
path
))
==
INVALID_FILE_ATTRIBUTES
)
goto
on_error
;
if
((
attrs
&
FILE_ATTRIBUTE_READONLY
)
==
0
)
return
0
;
giterr_set
(
GITERR_OS
,
"failed to get attributes"
);
return
-
1
;
}
if
(
!
SetFileAttributesW
(
path
,
(
attrs
&
~
FILE_ATTRIBUTE_READONLY
)))
goto
on_error
;
if
(
!
(
attrs
&
FILE_ATTRIBUTE_READONLY
))
return
0
;
attrs
&=
~
FILE_ATTRIBUTE_READONLY
;
if
(
!
SetFileAttributesW
(
fpath
,
attrs
))
{
giterr_set
(
GITERR_OS
,
"failed to set attributes"
);
on_error
:
set_errno
();
return
-
1
;
}
}
GIT_INLINE
(
int
)
rename_once
(
const
wchar_t
*
from
,
const
wchar_t
*
to
)
{
if
(
MoveFileExW
(
from
,
to
,
MOVEFILE_REPLACE_EXISTING
|
MOVEFILE_COPY_ALLOWED
))
return
0
;
if
(
last_error_retryable
())
return
GIT_RETRY
;
set_errno
();
return
-
1
;
}
int
p_rename
(
const
char
*
from
,
const
char
*
to
)
{
git_win32_path
wfrom
;
git_win32_path
wto
;
int
rename_tries
;
int
rename_succeeded
;
int
error
;
git_win32_path
wfrom
,
wto
;
if
(
git_win32_path_from_utf8
(
wfrom
,
from
)
<
0
||
git_win32_path_from_utf8
(
wto
,
to
)
<
0
)
return
-
1
;
/* wait up to 50ms if file is locked by another thread or process */
rename_tries
=
0
;
rename_succeeded
=
0
;
while
(
rename_tries
<
10
)
{
if
(
ensure_writable
(
wto
)
==
0
&&
MoveFileExW
(
wfrom
,
wto
,
MOVEFILE_REPLACE_EXISTING
|
MOVEFILE_COPY_ALLOWED
)
!=
0
)
{
rename_succeeded
=
1
;
break
;
}
error
=
GetLastError
();
if
(
error
==
ERROR_SHARING_VIOLATION
||
error
==
ERROR_ACCESS_DENIED
)
{
Sleep
(
5
);
rename_tries
++
;
}
else
break
;
}
return
rename_succeeded
?
0
:
-
1
;
do_with_retries
(
rename_once
(
wfrom
,
wto
),
ensure_writable
(
wto
));
}
int
p_recv
(
GIT_SOCKET
socket
,
void
*
buffer
,
size_t
length
,
int
flags
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment