From: Cristian Adam Date: Fri, 7 Feb 2020 20:38:24 +0000 (+0100) Subject: Win32: Close reading file for recompression (#535) X-Git-Tag: v4.0~648 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=743f35a1299bf6b412fd78e04ff3cadf2e18a04f;p=thirdparty%2Fccache.git Win32: Close reading file for recompression (#535) Fixes: https://github.com/ccache/ccache/issues/530 --- diff --git a/src/compress.cpp b/src/compress.cpp index fa24262de..724a5122c 100644 --- a/src/compress.cpp +++ b/src/compress.cpp @@ -117,6 +117,8 @@ recompress_file(const std::string& stats_file, reader->finalize(); writer->finalize(); + file.close(); + uint64_t old_size = Stat::stat(cache_file.path(), Stat::OnError::log).size_on_disk(); atomic_new_file.commit(); diff --git a/src/legacy_util.cpp b/src/legacy_util.cpp index d5020ca8e..613d5bf84 100644 --- a/src/legacy_util.cpp +++ b/src/legacy_util.cpp @@ -1267,9 +1267,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(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM