[ccache] Re: create CACHEDIR.TAG [patch]

Karl Chen quarl at cs.berkeley.edu
Sat Feb 2 03:10:31 GMT 2008


>>>>> On 2008-02-01 01:39 PST, Karl Chen writes:

    Karl> Hi, I suggest implementing the CACHEDIR.TAG proposed
    Karl> standard[1] for telling utilities that the .ccache
    Karl> directory can be omitted from archiving.  Below (inline
    Karl> attachment) is a patch which creates the CACHEDIR.TAG
    Karl> file appropriately.  Best, Karl

    Karl> [1] http://www.bford.info/cachedir/

Here's the patch again as text (Francois alerted me that it didn't
go through the mailing list previously).


diff -u -wr ccache-2.4/ccache.c ccache-2.4-p/ccache.c
--- ccache-2.4/ccache.c	2004-09-13 03:38:30.000000000 -0700
+++ ccache-2.4-p/ccache.c	2008-02-01 01:14:05.000000000 -0800
@@ -1029,6 +1029,12 @@
 		exit(1);
 	}
 
+    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;
 }
diff -u -wr ccache-2.4/ccache.h ccache-2.4-p/ccache.h
--- ccache-2.4/ccache.h	2004-09-13 03:38:30.000000000 -0700
+++ ccache-2.4-p/ccache.h	2008-02-01 01:14:17.000000000 -0800
@@ -81,6 +81,7 @@
 int copy_file(const char *src, const char *dest);
 
 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 -u -wr ccache-2.4/util.c ccache-2.4-p/util.c
--- ccache-2.4/util.c	2004-09-13 03:38:30.000000000 -0700
+++ ccache-2.4-p/util.c	2008-02-01 01:30:01.000000000 -0800
@@ -138,6 +138,39 @@
 	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



More information about the ccache mailing list