From 854326a0ba803161bb57db9cc7e1b375595befef Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Tue, 6 Aug 2019 16:31:59 +0200 Subject: [PATCH] renameormove: Windows: unlink existing file before rename --- src/utils/copyfile.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/utils/copyfile.cpp b/src/utils/copyfile.cpp index 2b8e1123..8972ba3f 100644 --- a/src/utils/copyfile.cpp +++ b/src/utils/copyfile.cpp @@ -129,6 +129,13 @@ out: bool renameormove(const char *src, const char *dst, string &reason) { +#ifdef _WIN32 + // Windows refuses to rename to an existing file. It appears that + // there are workarounds (See MoveFile, MoveFileTransacted), but + // anyway we are not expecting atomicity here. + unlink(dst); +#endif + // First try rename(2). If this succeeds we're done. If this fails // with EXDEV, try to copy. Unix really should have a library function // for this.