From: Joel Rosdahl Date: Tue, 23 May 2023 19:30:11 +0000 (+0200) Subject: fix: Make --trim-max-size accept 0 for no limit X-Git-Tag: v4.8.2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bdd6f382fad9421d6e9781ba2b0813e51ec7468;p=thirdparty%2Fccache.git fix: Make --trim-max-size accept 0 for no limit --- diff --git a/doc/MANUAL.adoc b/doc/MANUAL.adoc index 4ad33bf7c..4d91736cd 100644 --- a/doc/MANUAL.adoc +++ b/doc/MANUAL.adoc @@ -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_:: diff --git a/src/core/mainoptions.cpp b/src/core/mainoptions.cpp index 2f0f882ce..e2c22b954 100644 --- a/src/core/mainoptions.cpp +++ b/src/core/mainoptions.cpp @@ -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(); + } } }