From: Joel Rosdahl Date: Sun, 7 Dec 2014 15:58:59 +0000 (+0100) Subject: Create CACHEDIR.TAG files in [0-9a-f] subdirectories to avoid losing the config X-Git-Tag: v3.2.1~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed51f2b56ec81b924bbc172715458bbce682e863;p=thirdparty%2Fccache.git Create CACHEDIR.TAG files in [0-9a-f] subdirectories to avoid losing the config --- diff --git a/ccache.c b/ccache.c index 213612a05..c407760fe 100644 --- a/ccache.c +++ b/ccache.c @@ -930,15 +930,27 @@ to_cache(struct args *args) put_file_in_cache(output_obj, cached_obj); stats_update(STATS_TOCACHE); - /* Make sure we have a CACHEDIR.TAG - * This can be almost anywhere, but might as well do it near the end - * as if we exit early we save the stat call + /* Make sure we have a CACHEDIR.TAG in the cache part of cache_dir. This can + * be done almost anywhere, but we might as well do it near the end as we + * save the stat call if we exit early. */ - if (create_cachedirtag(conf->cache_dir) != 0) { - cc_log("Failed to create %s/CACHEDIR.TAG (%s)\n", - conf->cache_dir, strerror(errno)); - stats_update(STATS_ERROR); - failed(); + { + char *first_level_dir = dirname(stats_file); + if (create_cachedirtag(first_level_dir) != 0) { + cc_log("Failed to create %s/CACHEDIR.TAG (%s)\n", + first_level_dir, strerror(errno)); + stats_update(STATS_ERROR); + failed(); + } + free(first_level_dir); + + /* Remove any CACHEDIR.TAG on the cache_dir level where it was located in + * previous ccache versions. */ + if (getpid() % 1000 == 0) { + char *path = format("%s/CACHEDIR.TAG", conf->cache_dir); + unlink(path); + free(path); + } } free(tmp_stderr); diff --git a/cleanup.c b/cleanup.c index a8b4cf0b9..ee872ccbf 100644 --- a/cleanup.c +++ b/cleanup.c @@ -80,6 +80,10 @@ traverse_fn(const char *fname, struct stat *st) } } + if (strstr(p, "CACHEDIR.TAG")) { + goto out; + } + if (num_files == allocated) { allocated = 10000 + num_files*2; files = (struct files **)x_realloc(files, sizeof(struct files *)*allocated);