]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Create CACHEDIR.TAG file
authorKarl Chen <quarl@cs.berkeley.edu>
Sun, 1 Nov 2009 18:39:58 +0000 (19:39 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 5 Jan 2010 17:53:00 +0000 (18:53 +0100)
See <http://lists.samba.org/archive/ccache/2008q1/000316.html>.

ccache.c
ccache.h
util.c

index b80a0de9e9063583ee27833412b8a3f872fd9ff8..47f81bd07992d9bb4864fe2adcd8b87fa0f90cf9 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -1146,6 +1146,14 @@ int main(int argc, char *argv[])
                exit(1);
        }
 
+       if (!getenv("CCACHE_READONLY")) {
+               if (create_cachedirtag(cache_dir) != 0) {
+                       fprintf(stderr,"ccache: failed to create %s/CACHEDIR.TAG (%s)\n",
+                               cache_dir, strerror(errno));
+                       exit(1);
+               }
+       }
+
        ccache(argc, argv);
        return 1;
 }
index dc09d71f803523a70db634fd33be739e3cb21d46..5e89469573bf451b2db39e7f2947d60f23c33c4e 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -94,6 +94,7 @@ int move_file(const char *src, const char *dest);
 int test_if_compressed(const char *filename);
 
 int create_dir(const char *dir);
+int create_cachedirtag(const char *dir);
 void x_asprintf(char **ptr, const char *format, ...);
 char *x_strdup(const char *s);
 void *x_realloc(void *ptr, size_t size);
diff --git a/util.c b/util.c
index d8437e72d18c7b8ea239f58215d82b98795954f9..4c54efb8df0b05d3026c4ceddfaf841291f4f17e 100644 (file)
--- a/util.c
+++ b/util.c
@@ -329,6 +329,39 @@ int create_dir(const char *dir)
        return 0;
 }
 
+char const CACHEDIR_TAG[] =
+       "Signature: 8a477f597d28d172789f06886806bc55\n"
+       "# This file is a cache directory tag created by ccache.\n"
+       "# For information about cache directory tags, see:\n"
+       "#      http://www.brynosaurus.com/cachedir/\n";
+
+int create_cachedirtag(const char *dir)
+{
+       char *filename;
+       struct stat st;
+       FILE *f;
+       x_asprintf(&filename, "%s/CACHEDIR.TAG", dir);
+       if (stat(filename, &st) == 0) {
+               if (S_ISREG(st.st_mode)) {
+                       goto success;
+               }
+               errno = EEXIST;
+               goto error;
+       }
+       f = fopen(filename, "w");
+       if (!f) goto error;
+       if (fwrite(CACHEDIR_TAG, sizeof(CACHEDIR_TAG)-1, 1, f) != 1) {
+               goto error;
+       }
+       if (fclose(f)) goto error;
+success:
+       free(filename);
+       return 0;
+error:
+       free(filename);
+       return 1;
+}
+
 /*
   this is like asprintf() but dies if the malloc fails
   note that we use vsnprintf in a rather poor way to make this more portable