]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Detect and report permission failure for "ccache -F/-M"
authorFrancois Marier <francois@debian.org>
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)
Debian patch 12_cachesize_permissions.diff. See
<http://bugs.debian.org/332527>.

ccache.c
ccache.h
stats.c

index 2bafb9731f5afe8d88339de47f42ddf743acf17f..e2552163f685907cbd32a90c32f03a5a35054a56 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -1051,15 +1051,23 @@ static int ccache_main(int argc, char *argv[])
                case 'F':
                        check_cache_dir();
                        v = atoi(optarg);
-                       stats_set_limits(v, -1);
-                       printf("Set cache file limit to %u\n", (unsigned)v);
+                       if (stats_set_limits(v, -1) == 0) {
+                               printf("Set cache file limit to %u\n", (unsigned)v);
+                       } else {
+                               printf("Could not set cache file limit.\n");
+                               exit(1);
+                       }
                        break;
 
                case 'M':
                        check_cache_dir();
                        v = value_units(optarg);
-                       stats_set_limits(-1, v);
-                       printf("Set cache size limit to %uk\n", (unsigned)v);
+                       if (stats_set_limits(-1, v) == 0) {
+                               printf("Set cache size limit to %uk\n", (unsigned)v);
+                       } else {
+                               printf("Could not set cache size limit.\n");
+                               exit(1);
+                       }
                        break;
 
                default:
index 2ce9cb3a62536a9e1348bcc313243cfffe17f92f..9e6f2213bf12c4f33fb62c64cb96b3be50a9d592 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -118,7 +118,7 @@ void stats_zero(void);
 void stats_summary(void);
 void stats_tocache(size_t size);
 void stats_read(const char *stats_file, unsigned counters[STATS_END]);
-void stats_set_limits(long maxfiles, long maxsize);
+int stats_set_limits(long maxfiles, long maxsize);
 size_t value_units(const char *s);
 void display_size(unsigned v);
 void stats_set_sizes(const char *dir, size_t num_files, size_t total_size);
diff --git a/stats.c b/stats.c
index e5662fb2681a611d7b3653b954c31895f8c53abf..ddaf768db3b1f044b5a496693f10a050a9d67e22 100644 (file)
--- a/stats.c
+++ b/stats.c
@@ -286,7 +286,7 @@ void stats_zero(void)
 
 
 /* set the per directory limits */
-void stats_set_limits(long maxfiles, long maxsize)
+int stats_set_limits(long maxfiles, long maxsize)
 {
        int dir;
        unsigned counters[STATS_END];
@@ -298,7 +298,9 @@ void stats_set_limits(long maxfiles, long maxsize)
                maxsize /= 16;
        }
 
-       create_dir(cache_dir);
+       if (create_dir(cache_dir) != 0) {
+               return 1;
+       }
 
        /* set the limits in each directory */
        for (dir=0;dir<=0xF;dir++) {
@@ -306,7 +308,9 @@ void stats_set_limits(long maxfiles, long maxsize)
                int fd;
 
                x_asprintf(&cdir, "%s/%1x", cache_dir, dir);
-               create_dir(cdir);
+               if (create_dir(cdir) != 0) {
+                       return 1;
+               }
                x_asprintf(&fname, "%s/stats", cdir);
                free(cdir);
 
@@ -326,6 +330,8 @@ void stats_set_limits(long maxfiles, long maxsize)
                }
                free(fname);
        }
+
+       return 0;
 }
 
 /* set the per directory sizes */