]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
win32: Use MOVEFILE_REPLACE_EXISTING to replace file x_rename
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 22 Feb 2020 21:04:14 +0000 (22:04 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 22 Feb 2020 21:04:14 +0000 (22:04 +0100)
This is a partial cherry-pick of 743f35a1.

Co-authored-by: Cristian Adam <cristian.adam@gmail.com>
src/util.c

index 262aa6a6254b445cba0adfbcab852ecf8767b7e7..5c75952cc35ab13a03a2b599f92768ab00a77b42 100644 (file)
@@ -1,5 +1,5 @@
 // Copyright (C) 2002 Andrew Tridgell
-// Copyright (C) 2009-2019 Joel Rosdahl
+// Copyright (C) 2009-2020 Joel Rosdahl
 //
 // This program is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by the Free
@@ -1519,9 +1519,8 @@ x_rename(const char *oldpath, const char *newpath)
        return rename(oldpath, newpath);
 #else
        // Windows' rename() refuses to overwrite an existing file.
-       unlink(newpath); // Not x_unlink, as x_unlink calls x_rename.
        // If the function succeeds, the return value is nonzero.
-       if (MoveFileA(oldpath, newpath) == 0) {
+       if (MoveFileExA(oldpath, newpath, MOVEFILE_REPLACE_EXISTING) == 0) {
                LPVOID lp_msg_buf;
                DWORD dw = GetLastError();
                FormatMessage(