]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
feat: Improve logging for Util::clone_hard_link_or_copy_file
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 11 Sep 2022 10:50:27 +0000 (12:50 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 21 Sep 2022 15:06:28 +0000 (17:06 +0200)
src/Util.cpp
src/core/ResultRetriever.cpp

index c1b3651a669295a730b7ad88e17f88ba405d97c4..179bbc7f629281538596730e2ada13162f3e90b0 100644 (file)
@@ -293,12 +293,12 @@ clone_hard_link_or_copy_file(const Config& config,
       Util::hard_link(source, dest);
 #ifndef _WIN32
       if (chmod(dest.c_str(), 0444 & ~Util::get_umask()) != 0) {
-        LOG("Failed to chmod: {}", strerror(errno));
+        LOG("Failed to chmod {}: {}", dest.c_str(), strerror(errno));
       }
 #endif
       return;
     } catch (const core::Error& e) {
-      LOG_RAW(e.what());
+      LOG("Failed to hard link {} to {}: {}", source, dest, e.what());
       // Fall back to copying.
     }
   }
@@ -742,16 +742,11 @@ hard_link(const std::string& oldpath, const std::string& newpath)
 
 #ifndef _WIN32
   if (link(oldpath.c_str(), newpath.c_str()) != 0) {
-    throw core::Error(
-      FMT("failed to link {} to {}: {}", oldpath, newpath, strerror(errno)));
+    throw core::Error(strerror(errno));
   }
 #else
   if (!CreateHardLink(newpath.c_str(), oldpath.c_str(), nullptr)) {
-    DWORD error = GetLastError();
-    throw core::Error(FMT("failed to link {} to {}: {}",
-                          oldpath,
-                          newpath,
-                          Win32Util::error_message(error)));
+    throw core::Error(Win32Util::error_message(GetLastError()));
   }
 #endif
 }
index b1c34c9229d6189e969a203fe5a081082cecf47d..b3506f8243a06830cf2141b7ce8d281c8258991d 100644 (file)
@@ -109,8 +109,15 @@ ResultRetriever::on_raw_file(uint8_t file_number,
 
   const auto dest_path = get_dest_path(file_type);
   if (!dest_path.empty()) {
-    Util::clone_hard_link_or_copy_file(
-      m_ctx.config, raw_file_path, dest_path, false);
+    try {
+      Util::clone_hard_link_or_copy_file(
+        m_ctx.config, raw_file_path, dest_path, false);
+    } catch (core::Error& e) {
+      throw WriteError(FMT("Failed to clone/link/copy {} to {}: {}",
+                           raw_file_path,
+                           dest_path,
+                           e.what()));
+    }
 
     // Update modification timestamp to save the file from LRU cleanup (and, if
     // hard-linked, to make the object file newer than the source file).