]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Create CACHEDIR.TAG files in [0-9a-f] subdirectories to avoid losing the config
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 7 Dec 2014 15:58:59 +0000 (16:58 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 7 Dec 2014 15:58:59 +0000 (16:58 +0100)
ccache.c
cleanup.c

index 213612a054c6ed904e258b21069cd9497a8f8b2e..c407760fe87674af5d618e65bd672c690508d139 100644 (file)
--- 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);
index a8b4cf0b9020d2795cc9c46c84f393111d2e0437..ee872ccbf12295abed9b291b76dfc9d27e6e3b49 100644 (file)
--- 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);