From: Joel Rosdahl Date: Thu, 28 May 2020 20:05:54 +0000 (+0200) Subject: Create parent directories if hard linking fails with ENOENT X-Git-Tag: v3.7.10~8 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=ec874b68d05981febb4685f0a3e4436b9bb54b1f;p=thirdparty%2Fccache.git Create parent directories if hard linking fails with ENOENT This makes hard linking work for an empty cache structure as well. --- diff --git a/src/ccache.c b/src/ccache.c index 7ad1f3b34..de026bced 100644 --- a/src/ccache.c +++ b/src/ccache.c @@ -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");