summaryrefslogtreecommitdiff
path: root/src/fileops.c
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2011-02-24 23:53:40 +0200
committerVicent Marti <tanoku@gmail.com>2011-02-24 23:53:40 +0200
commit7360122ba973dfea6604ee1b378f79ce6399af3e (patch)
tree64acb5e54df05d7f344eb2c509ba9f1c69275e0d /src/fileops.c
parent3eb47c9f6768292b8c8f8199ef851812c03aff70 (diff)
downloadlibgit2-7360122ba973dfea6604ee1b378f79ce6399af3e.tar.gz
Fix file renaming in MinGW
We now use MoveFileEx, which is not assured to be atomic but works for always (both if the destination exists, or if it doesn't) and is available in MinGW. Since this is a Win32 API call, complaint about lost or overwritten files should be forwarded at Steve Ballmer. Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/fileops.c')
-rw-r--r--src/fileops.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/src/fileops.c b/src/fileops.c
index 1da6116d9..602862ca4 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -150,21 +150,19 @@ int gitfo_move_file(char *from, char *to)
* file exists, the `rename` call fails. This is as
* close as it gets with the Win32 API.
*/
- if (gitfo_exists(to) == GIT_SUCCESS)
- return ReplaceFile(to, from, NULL, 0, NULL, NULL) ?
- GIT_SUCCESS : GIT_EOSERR;
+ return MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING) ? GIT_SUCCESS : GIT_EOSERR;
#else
/* Don't even try this on Win32 */
if (!link(from, to)) {
gitfo_unlink(from);
return GIT_SUCCESS;
}
-#endif
if (!rename(from, to))
return GIT_SUCCESS;
return GIT_EOSERR;
+#endif
}
int gitfo_map_ro(git_map *out, git_file fd, git_off_t begin, size_t len)