]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Win32: Close reading file for recompression (#535)
authorCristian Adam <cristian.adam@gmail.com>
Fri, 7 Feb 2020 20:38:24 +0000 (21:38 +0100)
committerGitHub <noreply@github.com>
Fri, 7 Feb 2020 20:38:24 +0000 (21:38 +0100)
Fixes: https://github.com/ccache/ccache/issues/530
src/compress.cpp
src/legacy_util.cpp

index fa24262de8af91d8fb47e3fe8bec2e432149b4bf..724a5122cbad5a631fcef5d8a66a7312e4ed290a 100644 (file)
@@ -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();
index d5020ca8ee4c1c2f29a7b586cd6b0db8eef96807..613d5bf84519e13c53685df1bbaa4cbad4b6c271 100644 (file)
@@ -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