]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Don't create cache subdirectories in read-only mode
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 4 Nov 2012 10:38:13 +0000 (11:38 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 4 Nov 2012 10:38:13 +0000 (11:38 +0100)
ccache.c
test.sh

index 738c022f3638acdb838d0904f61dc91d45e92bc1..50137d3980a1f90b8be460dd43a97db08a0fa12c 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -266,7 +266,7 @@ get_path_in_cache(const char *name, const char *suffix)
                char *p = format("%s/%c", path, name[i]);
                free(path);
                path = p;
-               if (create_dir(path) != 0) {
+               if (!getenv("CCACHE_READONLY") && create_dir(path) != 0) {
                        fatal("Failed to create %s: %s", path, strerror(errno));
                }
        }
diff --git a/test.sh b/test.sh
index afd73a40e8f7a3d075bb14be7d9f25c39de4f6fc..3ed90697bf6ec0eb1a69e4affbb1cfe65a8d74cb 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -1387,17 +1387,26 @@ readonly_suite() {
     # Make the cache readonly
     # Check that readonly mode finds the result.
     testname="cache hit"
-    rm -f test.o
+    rm -f test.o test2.o
     chmod -R a-w $CCACHE_DIR
-    CCACHE_READONLY=1 CCACHE_TEMPDIR=/tmp CCACHE_PREFIX=false $CCACHE $COMPILER -c test.c -o test.o
-    status=$?
+    CCACHE_READONLY=1 CCACHE_TEMPDIR=/tmp CCACHE_PREFIX=false $CCACHE $COMPILER -c test.c -o test.o >/dev/null 2>&1
+    status1=$?
+    # Check that fallback to the real compiler works for a cache miss.
+    CCACHE_READONLY=1 CCACHE_TEMPDIR=/tmp $CCACHE $COMPILER -c test2.c -o test2.o >/dev/null 2>&1
+    status2=$?
     chmod -R a+w $CCACHE_DIR
-    if [ $status -ne 0 ]; then
+    if [ $status1 -ne 0 ]; then
         test_failed "failure when compiling test.c readonly"
     fi
+    if [ $status2 -ne 0 ]; then
+        test_failed "failure when compiling test2.c readonly"
+    fi
     if [ ! -f test.o ]; then
         test_failed "test.o missing"
     fi
+    if [ ! -f test2.o ]; then
+        test_failed "test2.o missing"
+    fi
 
     # Check that readonly mode doesn't try to store new results.
     testname="cache miss"