summaryrefslogtreecommitdiff
path: root/CCache
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2008-11-03 14:04:15 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2008-11-03 14:04:15 +0000
commit0c20caeddcf70d6faf303c3f15ad0b428ae94de9 (patch)
tree463618366aba9382db210a8e1ccddd3c581b7142 /CCache
parent6f3603a05a351eaaef4e3496e2faa6302e71ee0f (diff)
downloadswig-0c20caeddcf70d6faf303c3f15ad0b428ae94de9.tar.gz
apply debian/patches/07_cachedirtag.diff
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10908 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'CCache')
-rw-r--r--CCache/ccache.c8
-rw-r--r--CCache/ccache.h1
-rw-r--r--CCache/util.c33
3 files changed, 42 insertions, 0 deletions
diff --git a/CCache/ccache.c b/CCache/ccache.c
index 3a4e8c7b2..222fbe70f 100644
--- a/CCache/ccache.c
+++ b/CCache/ccache.c
@@ -1128,6 +1128,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;
}
diff --git a/CCache/ccache.h b/CCache/ccache.h
index 67904cdf7..71b03ffe9 100644
--- a/CCache/ccache.h
+++ b/CCache/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/CCache/util.c b/CCache/util.c
index 70d7ea7d4..6056d36f7 100644
--- a/CCache/util.c
+++ b/CCache/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