summaryrefslogtreecommitdiff
path: root/src/fileops.c
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2011-02-24 21:43:08 +0200
committerVicent Marti <tanoku@gmail.com>2011-02-24 21:43:08 +0200
commit3eb47c9f6768292b8c8f8199ef851812c03aff70 (patch)
tree7e6d9c67c3bca4ca83e21aa70b6af1560e04250d /src/fileops.c
parentc3be146840754d881655fb6b851899fb4a0d7cbd (diff)
downloadlibgit2-3eb47c9f6768292b8c8f8199ef851812c03aff70.tar.gz
Fix renaming of files in Win32
The `rename` call doesn't quite work on Win32: expects the destination file to not exist. We're using a native Win32 call in those cases -- that should do the trick. Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/fileops.c')
-rw-r--r--src/fileops.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/fileops.c b/src/fileops.c
index 461dcf0ad..1da6116d9 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -144,10 +144,22 @@ void gitfo_free_buf(gitfo_buf *obj)
int gitfo_move_file(char *from, char *to)
{
+#ifdef GIT_WIN32
+ /*
+ * Win32 POSIX compilance my ass. If the destination
+ * 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;
+#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;