]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Make --trim-max-size accept 0 for no limit
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 23 May 2023 19:30:11 +0000 (21:30 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 23 May 2023 19:30:11 +0000 (21:30 +0200)
doc/MANUAL.adoc
src/core/mainoptions.cpp

index 4ad33bf7c2418025e99f0c0ab43e2cc63f54eed9..4d91736cdd6197e2160b43f5605169d097dc25b5 100644 (file)
@@ -211,7 +211,7 @@ directory to a certain size, use `CCACHE_MAXSIZE=_SIZE_ ccache -c`.
 
     Specify the maximum size for `--trim-dir`. _SIZE_ should be a number
     followed by an optional suffix: kB, MB, GB, TB (decimal), KiB, MiB, GiB or
-    TiB (binary). The default suffix is GiB.
+    TiB (binary). The default suffix is GiB. Use 0 for no limit.
 
 *--trim-method* _METHOD_::
 
index 2f0f882ce693e2efec517291f54835e48ef61149..e2c22b954ce97335872ffafae91a5277615c6c3e 100644 (file)
@@ -141,9 +141,10 @@ Options for remote file-based storage:
                                at most the size specified by --trim-max-size
                                (note: don't use this option to trim the local
                                cache)
-        --trim-max-size SIZE   specify the maximum size for --trim-dir;
-                               available suffixes: kB, MB, GB, TB (decimal) and
-                               KiB, MiB, GiB, TiB (binary); default suffix: GiB
+        --trim-max-size SIZE   specify the maximum size for --trim-dir (use 0 for
+                               no limit); available suffixes: kB, MB, GB, TB
+                               (decimal) and KiB, MiB, GiB, TiB (binary);
+                               default suffix: GiB
         --trim-method METHOD   specify the method (atime or mtime) for
                                --trim-dir; default: atime
         --trim-recompress LEVEL
@@ -365,13 +366,15 @@ trim_dir(const std::string& dir,
   uint64_t final_size = size_after_recompression;
 
   size_t removed_files = 0;
-  for (const auto& file : files) {
-    if (final_size <= trim_max_size) {
-      break;
-    }
-    if (Util::unlink_tmp(file.path())) {
-      ++removed_files;
-      final_size -= file.size_on_disk();
+  if (trim_max_size > 0) {
+    for (const auto& file : files) {
+      if (final_size <= trim_max_size) {
+        break;
+      }
+      if (Util::unlink_tmp(file.path())) {
+        ++removed_files;
+        final_size -= file.size_on_disk();
+      }
     }
   }