]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Don't fail if object file exists and is unwritable
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 5 Sep 2022 11:00:59 +0000 (13:00 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 5 Sep 2022 11:00:59 +0000 (13:00 +0200)
src/Util.cpp
test/suites/hardlink.bash

index 4e713d9fa735f1af2ec7ac60184a3781a3b6037b..2208de0e49c0fdca5da2e21f89fb91d448c7c12d 100644 (file)
@@ -352,6 +352,8 @@ copy_file(const std::string& src, const std::string& dest, bool via_tmp_file)
     throw core::Error(FMT("{}: {}", src, strerror(errno)));
   }
 
+  unlink(dest.c_str());
+
   Fd dest_fd;
   std::string tmp_file;
   if (via_tmp_file) {
index cf3c5304e3248d90d78d4a17e87b55616302dda4..31c58f0e5f52968a01094ad3f93a8929f801e58e 100644 (file)
@@ -31,6 +31,15 @@ SUITE_hardlink() {
         test_failed "Object files not hard linked"
     fi
 
+    $CCACHE_COMPILE -c test1.c
+    expect_stat preprocessed_cache_hit 2
+    expect_stat cache_miss 1
+    expect_stat files_in_cache 2
+
+    if [ test1.o -ef test1.o.saved ]; then
+        test_failed "Object files are hard linked"
+    fi
+
     # -------------------------------------------------------------------------
     TEST "Corrupted file size is detected"