]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Fall back to copying if hard-linking fails
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 7 Feb 2016 11:03:25 +0000 (12:03 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 7 Feb 2016 11:03:25 +0000 (12:03 +0100)
As suggested by Matt Blythe.

NEWS.txt
ccache.c

index 109084067ee5c3cbc9316f510d4a4dc896a61eb9..55108c2aeef91562cea4eb5545ab987ea27caf83 100644 (file)
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -25,6 +25,9 @@ New features and improvements
 - The concatenated form of some long compiler options is now recognized, for
   example when using `-isystemPATH` instead of `-isystem PATH`.
 
+- If hard-linking is enabled and but fails (e.g. due to cross-device linking),
+  ccache now falls back to copying instead of running the compiler.
+
 
 Bug fixes
 ~~~~~~~~~
index e75838c428707af4a7cb0f6311433a17e5e0b87f..14df68260b97085c9d96e3159913b70745f5cc03 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -871,18 +871,20 @@ put_file_in_cache(const char *source, const char *dest)
        if (do_link) {
                x_unlink(dest);
                ret = link(source, dest);
-       } else {
+               if (ret != 0) {
+                       cc_log("Failed to link %s to %s: %s", source, dest, strerror(errno));
+                       cc_log("Falling back to copying");
+                       do_link = false;
+               }
+       }
+       if (!do_link) {
                ret = copy_file(
                  source, dest, conf->compression ? conf->compression_level : 0);
-       }
-       if (ret != 0) {
-               cc_log("Failed to %s %s to %s: %s",
-                      do_link ? "link" : "copy",
-                      source,
-                      dest,
-                      strerror(errno));
-               stats_update(STATS_ERROR);
-               failed();
+               if (ret != 0) {
+                       cc_log("Failed to copy %s to %s: %s", source, dest, strerror(errno));
+                       stats_update(STATS_ERROR);
+                       failed();
+               }
        }
        cc_log("Stored in cache: %s -> %s", source, dest);
        if (x_stat(dest, &st) != 0) {