From a3a9f7288306802a80693fa0aa8213b65d932479 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Wed, 4 Nov 2026 20:33:08 -1000 Subject: Leave the scan uncached with a negative cache-size The page cache counts a cache-size of 0 or less as off, but scan-path cached its list for any value other than 0, so a negative one still wrote a list into cache-root. --- MANUAL.txt | 7 ++++--- source/cgit.c | 2 +- tests/t0003-cache.sh | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/MANUAL.txt b/MANUAL.txt index 33e5eaa..202ef80 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -89,9 +89,10 @@ cache-scan-ttl:: "scan-path", "The cache". cache-size:: - The maximum number of entries in the cgit cache. When set to "0", - caching is disabled. A scan-path caches its result only when this is - defined prior to it. Default value: "0". See also: "The cache". + The maximum number of entries in the cgit cache. When set to "0" or + less, caching is disabled, the scan-path result included. A scan-path + caches its result only when this is defined prior to it. Default value: + "0". See also: "The cache". cache-snapshot-ttl:: Number which specifies the time-to-live, in minutes, for the cached diff --git a/source/cgit.c b/source/cgit.c index dc483ee..81f2b14 100644 --- a/source/cgit.c +++ b/source/cgit.c @@ -698,7 +698,7 @@ static void apply_config(const char *name, const char *value) else if (!strcmp(name, "project-list")) ctx.cfg.project_list = cgit_strdup_first_line(cgit_expand_macros(value)); else if (!strcmp(name, "scan-path")) { - if (ctx.cfg.cache_size) + if (ctx.cfg.cache_size > 0) process_cached_repolist(cgit_expand_macros(value)); else scan_tree(cgit_expand_macros(value)); diff --git a/tests/t0003-cache.sh b/tests/t0003-cache.sh index fa72015..0504c88 100755 --- a/tests/t0003-cache.sh +++ b/tests/t0003-cache.sh @@ -455,4 +455,19 @@ test_expect_success 'a negative cache-scan-ttl never expires the list' ' ! grep "^repo.url=kept$" "cache5/$scanned_rc" ' +# A cache-size below zero turns the page cache off, and the scan with it, so +# the cache directory stays empty. +test_expect_success 'a negative cache-size leaves the scan uncached' ' + { + echo "virtual-root=/" && + echo "cache-root=$PWD/cache-negative" && + echo "cache-size=-1" && + echo "scan-path=$PWD/scanned" + } >negativerc && + rm -rf cache-negative && mkdir cache-negative && + cgit_rc negativerc "url=" >tmp && + grep ">one" tmp && + test_dir_is_empty cache-negative +' + test_done -- cgit 2.12.1