]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Create parent directories if hard linking fails with ENOENT
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 28 May 2020 20:05:54 +0000 (22:05 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 28 May 2020 20:05:54 +0000 (22:05 +0200)
This makes hard linking work for an empty cache structure as well.

src/ccache.c

index 7ad1f3b3433ada61efd748d01d8385844ad6abda..de026bcedaece7b28b417f9dd513fb4d825f2599 100644 (file)
@@ -1230,6 +1230,10 @@ do_copy_or_move_file_to_cache(const char *source, const char *dest, bool copy)
                if (do_link) {
                        x_unlink(dest);
                        int ret = link(source, dest);
+                       if (ret != 0 && errno == ENOENT) {
+                               create_parent_dirs(dest);
+                               ret = link(source, dest);
+                       }
                        if (ret != 0) {
                                cc_log("Failed to link %s to %s: %s", source, dest, strerror(errno));
                                cc_log("Falling back to copying");