Backtestshugorun-20260930-140149#15101

Issue #15101 Merged fix PR # Run 30 Sep 2026 · run-20260930-140149 gohugoio/hugo

hugo --gc deletes in-use image cache files when on-disk path case differs from the cache key (case-insensitive filesystems)

Better

Our patch was judged better than the merged fix.

In this judgment, Patch A = our agent, Patch B = the merged fix.

Both patches fix the root cause in the pruner's usage check: an on-disk name that differs from a seen cache key only in case is no longer treated as unused.

Patch A:
- It looks up the seen ids that share the walked name's lowercase form, stats each one, and keeps the file only if `os.SameFile` confirms the id resolves to the very same file.
- This asks the filesystem directly how it resolved the read, which is the issue's exact criterion. It is correct on both case-insensitive and case-sensitive filesystems.
- The lowercase index is built lazily, so the extra work only happens on a mismatch. The change is small and local.
- Its test is clever. On case-sensitive CI (Linux) it emulates case-insensitive resolution with a hard link, and it adds a negative case (a distinct `Other/x.jpeg` still gets pruned). So the fix is exercised on every platform rather than skipped.

Patch B:
- It uses an indirect heuristic: defer the decision and remove the mixed-case file only if the exact-case key was also walked.
- This works in the common scenarios, but it infers sameness from absence rather than checking it. On a case-sensitive filesystem, a stale mixed-case file survives if the exact-case key file isn't present on disk.
- `seenByLower` keeps only one id per lowercase key, so seen ids that differ only by case collide.
- It restructures the walk more heavily (a remove closure and a post-walk pass).
- Its main tests (the case-insensitive unit test and the testscript) are skipped on case-sensitive CI, so the fix path is not exercised there.
- It adds unrelated test infrastructure (a `base64decode` command, a testscript condition, an htesting helper), which adds churn.

Patch A is more precise, simpler, and better tested across platforms.

The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.

Solve

24m16 turns

Wall-clock time in the container

Full test suite

No new failures

3,680 passed · 95 skipped · 3,784 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

131vs 230 merged

Changed lines, ours vs merged

What happens

On a case-insensitive filesystem (macOS APFS, Windows), hugo --gc deletes image cache files under resources/_gen that the build actively uses, if the on-disk path case differs from the cache key. The build itself works fine (the case-insensitive filesystem resolves the read), but the pruner's usage check is a case-sensitive string comparison, so the just-used file is considered unused and removed.

The relevant code is in cache/filecache/filecache_pruner.go (unchanged on master):

if !shouldRemove && c.entryLocker.seen.Len() > 0 {
    // Remove it if it's not been touched/used in the last build.
    shouldRemove = !c.entryLocker.seen.Has(name)
}

seen contains the cache key (for images: the lowercased target path, via ImageCache.getOrCreate → c.fcache.ReadOrCreate(relTargetPath, …)), while name is the real on-disk name from the filesystem walk. If they differ only in case, seen.Has(name) is false and the file is deleted.

Why the case can differ in practice

Page paths have been lowercased since the v0.123 page-system rewrite, so cache keys for page-bundle images are lowercase. Caches created by older Hugo versions preserve the source directory case (e.g. resources/_gen/images/collections/PastFuture/…). Such caches are common in the wild: committed to git for CI cold-start speed, restored by CI cache plugins, or simply carried forward on a developer machine across Hugo upgrades.

The result is a permanent rebuild/evict cycle: --gc deletes the in-use entries → the next build silently re-processes all of them → the new files land inside the surviving mixed-case directory (the prune walk visits directories before deleting their files, so the directory is never seen empty and survives; on a case-insensitive filesystem the re-created file then lands in it) → the next --gc deletes them again. On the real site where we found this, every build re-scaled 267 images (~35 s per build, forever).

Minimal reproduction (macOS)

hugo new site repro && cd repro
mkdir -p content/MyBundle layouts/_default
printf 'baseURL = "https://example.org/"\ndisableKinds = ["taxonomy", "term", "rss", "sitemap"]\n' > hugo.toml
printf -- '---\ntitle: My Bundle\n---\n' > content/MyBundle/index.md
cp /path/to/any.jpeg content/MyBundle/cover.jpeg
printf '{{ with .Resources.GetMatch "cover.jpeg" }}{{ with .Resize "100x" }}<img src="{{ .RelPermalink }}">{{ end }}{{ end }}' > layouts/_default/single.html
printf 'home' > layouts/_default/home.html

hugo                      # creates resources/_gen/images/mybundle/cover_hu_<hash>.jpeg
# simulate a cache written by an older Hugo (or copied from elsewhere):
mv resources/_gen/images/mybundle resources/_gen/images/tmp
mv resources/_gen/images/tmp resources/_gen/images/MyBundle

hugo --gc                 # build succeeds (16 ms, cache hit), but reports "Cleaned 1"
find resources -type f    # -> empty: the file the build just used is gone

hugo                      # re-processes the image (474 ms) — and writes it back
                          # into the surviving MyBundle/ dir, so the cycle repeats

Observed output of the --gc build:

Processed images │  1
Cleaned          │  1
Total in 16 ms

A cache file that was read 16 ms earlier is deleted as "not been touched/used in the last build".

What I expected

--gc should never delete a cache entry that the same build read. On case-insensitive filesystems the usage check should match the way the filesystem resolved the read — e.g. compare case-insensitively (or normalize walk names against the seen set) when the cache filesystem is case-insensitive. Renaming the on-disk entry to the key's case would even self-heal old caches.

Version

hugo v0.164.0+extended+withdeploy darwin/arm64 BuildDate=2026-07-06T16:39:30Z VendorInfo=Homebrew

The pruner code is identical on current master.

The two patches

Our patch+131 −0
cache/filecache/filecache_pruner.goindex d6322cb70..e6974920c 100644@@ -17,6 +17,7 @@ import ( 	"fmt" 	"io" 	"os"+	"strings"  	"github.com/gohugoio/hugo/common/herrors" 	"github.com/gohugoio/hugo/hugofs"@@ -59,6 +60,9 @@ func (c *Cache) Prune(force bool) (int, error) {  	counter := 0 +	// Lazily built index of the seen ids, keyed by their lower case form.+	var seenLower map[string][]string+ 	err := afero.Walk(c.Fs, "", func(name string, info os.FileInfo, err error) error { 		if info == nil { 			return nil@@ -96,6 +100,24 @@ func (c *Cache) Prune(force bool) (int, error) { 		if !shouldRemove && c.entryLocker.seen.Len() > 0 { 			// Remove it if it's not been touched/used in the last build. 			shouldRemove = !c.entryLocker.seen.Has(name)+			if shouldRemove {+				// On case-insensitive filesystems (e.g. macOS, Windows) the on-disk+				// name may differ in case from the id used in the build.+				// Keep it if any such id resolves to this very file.+				if seenLower == nil {+					seenLower = make(map[string][]string)+					for id := range c.entryLocker.seen.All() {+						k := strings.ToLower(id)+						seenLower[k] = append(seenLower[k], id)+					}+				}+				for _, id := range seenLower[strings.ToLower(name)] {+					if fi, err := c.Fs.Stat(id); err == nil && os.SameFile(info, fi) {+						shouldRemove = false+						break+					}+				}+			} 		}  		if shouldRemove {cache/filecache/filecache_pruner_test.goindex 117ff3430..21d218dd4 100644@@ -15,6 +15,8 @@ package filecache_test  import ( 	"fmt"+	"os"+	"path/filepath" 	"testing" 	"testing/synctest" 	"time"@@ -113,3 +115,110 @@ dir = ":resourceDir/_gen" 		} 	}) }++// Issue: On case-insensitive filesystems (macOS, Windows) the on-disk path of a+// cache entry may differ in case from the cache key used in the build+// (e.g. MyBundle/cover.jpeg vs mybundle/cover.jpeg). Such in-use entries+// must not be pruned.+func TestPruneCaseInsensitiveFilesystem(t *testing.T) {+	t.Parallel()+	c := qt.New(t)++	configStr := `+resourceDir = "myresources"+contentDir = "content"+dataDir = "data"+i18nDir = "i18n"+layoutDir = "layouts"+assetDir = "assets"+archeTypedir = "archetypes"++[caches]+[caches.images]+maxAge = -1+dir = ":resourceDir/_gen"+`++	tmp := t.TempDir()+	fs := afero.NewBasePathFs(afero.NewOsFs(), tmp)+	p := newPathsSpec(t, fs, configStr)+	fileCacheConfig := p.Cfg.GetConfigSection("caches").(filecache.Configs)++	newCache := func() (filecache.Caches, *filecache.Cache) {+		caches, err := filecache.NewCaches(fileCacheConfig, fs)+		c.Assert(err, qt.IsNil)+		caches.SetResourceFs(fs)+		return caches, caches[filecache.CacheKeyImages]+	}++	// First build: create the entries.+	_, cache := newCache()+	for _, id := range []string{"mybundle/cover.jpeg", "other/x.jpeg"} {+		_, _, err := cache.GetOrCreateBytes(id, func() ([]byte, error) {+			return []byte("abc"), nil+		})+		c.Assert(err, qt.IsNil)+	}++	// Locate the on-disk cache dir.+	var cacheDir string+	c.Assert(filepath.Walk(tmp, func(path string, info os.FileInfo, err error) error {+		if err != nil {+			return err+		}+		if info.IsDir() && info.Name() == "mybundle" {+			cacheDir = filepath.Dir(path)+			return filepath.SkipAll+		}+		return nil+	}), qt.IsNil)+	c.Assert(cacheDir, qt.Not(qt.Equals), "")++	lower := filepath.Join(cacheDir, "mybundle")+	upper := filepath.Join(cacheDir, "MyBundle")+	upperFile := filepath.Join(upper, "cover.jpeg")++	// Move the entry to MyBundle/cover.jpeg.+	c.Assert(os.Rename(lower, lower+"_tmp"), qt.IsNil)+	c.Assert(os.Rename(lower+"_tmp", upper), qt.IsNil)++	_, err := os.Stat(filepath.Join(lower, "cover.jpeg"))+	caseInsensitive := err == nil++	if !caseInsensitive {+		// Emulate case-insensitive resolution of the key: the key path+		// mybundle/cover.jpeg is a hard link to MyBundle/cover.jpeg.+		c.Assert(os.MkdirAll(lower, 0o777), qt.IsNil)+		c.Assert(os.Link(upperFile, filepath.Join(lower, "cover.jpeg")), qt.IsNil)++		// Negative case: Other/x.jpeg is a distinct file from the key other/x.jpeg.+		otherUpper := filepath.Join(cacheDir, "Other")+		c.Assert(os.MkdirAll(otherUpper, 0o777), qt.IsNil)+		c.Assert(os.WriteFile(filepath.Join(otherUpper, "x.jpeg"), []byte("abc"), 0o666), qt.IsNil)+	}++	// Second build: fresh seen set.+	caches, cache := newCache()+	for _, id := range []string{"mybundle/cover.jpeg", "other/x.jpeg"} {+		_, _, err := cache.GetOrCreateBytes(id, func() ([]byte, error) {+			c.Fatalf("expected cache hit for %q", id)+			return nil, nil+		})+		c.Assert(err, qt.IsNil)+	}++	_, err = caches.Prune()+	c.Assert(err, qt.IsNil)++	// The in-use entry must not have been deleted.+	_, err = os.Stat(upperFile)+	c.Assert(err, qt.IsNil, qt.Commentf("in-use cache entry %q was pruned", upperFile))+	c.Assert(cache.GetString("mybundle/cover.jpeg"), qt.Equals, "abc")++	if !caseInsensitive {+		// Distinct file on a case-sensitive filesystem: still pruned.+		_, err = os.Stat(filepath.Join(cacheDir, "Other", "x.jpeg"))+		c.Assert(os.IsNotExist(err), qt.IsTrue)+		c.Assert(cache.GetString("other/x.jpeg"), qt.Equals, "abc")+	}+} 
Merged fix · PR #+217 −13
cache/filecache/filecache_pruner.goindex d6322cb70..cd95766be 100644@@ -17,6 +17,7 @@ import ( 	"fmt" 	"io" 	"os"+	"strings"  	"github.com/gohugoio/hugo/common/herrors" 	"github.com/gohugoio/hugo/hugofs"@@ -59,6 +60,29 @@ func (c *Cache) Prune(force bool) (int, error) {  	counter := 0 +	seen := c.entryLocker.seen+	seenByLower := make(map[string]string, seen.Len())+	for id := range seen.All() {+		seenByLower[strings.ToLower(id)] = id+	}++	// Names on disk matching a used cache key except for the case, and the used keys+	// actually walked. See the note about case-insensitive filesystems below.+	var candidates map[string]string+	visited := make(map[string]bool, seen.Len())++	remove := func(name string) error {+		err := c.Fs.Remove(name)+		if err == nil {+			counter+++			return nil+		}+		if !herrors.IsNotExist(err) {+			return err+		}+		return nil+	}+ 	err := afero.Walk(c.Fs, "", func(name string, info os.FileInfo, err error) error { 		if info == nil { 			return nil@@ -93,27 +117,44 @@ func (c *Cache) Prune(force bool) (int, error) {  		shouldRemove := force || c.isExpired(info.ModTime()) -		if !shouldRemove && c.entryLocker.seen.Len() > 0 {-			// Remove it if it's not been touched/used in the last build.-			shouldRemove = !c.entryLocker.seen.Has(name)+		if seen.Has(name) {+			visited[name] = true+		} else if !shouldRemove && seen.Len() > 0 {+			if id, found := seenByLower[strings.ToLower(name)]; found {+				// On case-insensitive filesystems this is the same file as id; e.g. an+				// entry created before Hugo started lowercasing the content paths in+				// v0.123 (content/MyBundle => _gen/images/MyBundle). Decided once the+				// walk is done: if id is walked too, they are distinct files and this+				// one is stale. See issue 15101.+				if candidates == nil {+					candidates = make(map[string]string)+				}+				candidates[name] = id+			} else {+				// Remove it if it's not been touched/used in the last build.+				shouldRemove = true+			} 		}  		if shouldRemove {-			err := c.Fs.Remove(name)-			if err == nil {-				counter++-			}--			if err != nil && !herrors.IsNotExist(err) {-				return err-			}-+			return remove(name) 		}  		return nil 	})+	if err != nil {+		return counter, err+	}++	for name, id := range candidates {+		if visited[id] {+			if err := remove(name); err != nil {+				return counter, err+			}+		}+	} -	return counter, err+	return counter, nil }  func (c *Cache) pruneRootDirs(force bool) (int, error) {cache/filecache/filecache_pruner_test.goindex 117ff3430..dc01e417a 100644@@ -20,11 +20,72 @@ import ( 	"time"  	"github.com/gohugoio/hugo/cache/filecache"+	"github.com/gohugoio/hugo/htesting" 	"github.com/spf13/afero"  	qt "github.com/frankban/quicktest" ) +// A cache entry created before Hugo started lowercasing content paths in v0.123+// (e.g. _gen/images/MyBundle) is on a case-insensitive filesystem the same file as+// the lowercased cache key used today, and must not be pruned.+// See issue 15101.+func TestPruneCacheEntryWithOtherCase(t *testing.T) {+	t.Parallel()+	c := qt.New(t)++	dir := t.TempDir()+	if isCaseInsensitive, err := htesting.IsCaseInsensitiveFs(dir); err != nil {+		t.Fatal(err)+	} else if !isCaseInsensitive {+		t.Skip("skip test on case-sensitive filesystem")+	}++	fs := afero.NewBasePathFs(afero.NewOsFs(), dir)+	newCache := func() *filecache.Cache {+		return filecache.NewCache(fs, filecache.FileCacheConfig{Dir: "cache", MaxAge: -1})+	}++	c.Assert(newCache().SetBytes("MyBundle/i1", []byte("abc")), qt.IsNil)++	cache := newCache()+	_, b, err := cache.GetOrCreateBytes("mybundle/i1", func() ([]byte, error) {+		return []byte("def"), nil+	})+	c.Assert(err, qt.IsNil)+	c.Assert(string(b), qt.Equals, "abc")++	count, err := cache.Prune(false)+	c.Assert(err, qt.IsNil)+	c.Assert(count, qt.Equals, 0)+	c.Assert(cache.GetString("MyBundle/i1"), qt.Equals, "abc")+}++// On a case-sensitive filesystem the entries above are distinct files,+// and the one not used in this build should be pruned.+func TestPruneCacheEntryWithOtherCaseCaseSensitiveFs(t *testing.T) {+	t.Parallel()+	c := qt.New(t)++	fs := afero.NewMemMapFs()+	cache := filecache.NewCache(fs, filecache.FileCacheConfig{Dir: "cache", MaxAge: -1})++	c.Assert(cache.SetBytes("MyBundle/i1", []byte("abc")), qt.IsNil)++	cache = filecache.NewCache(fs, filecache.FileCacheConfig{Dir: "cache", MaxAge: -1})+	_, b, err := cache.GetOrCreateBytes("mybundle/i1", func() ([]byte, error) {+		return []byte("def"), nil+	})+	c.Assert(err, qt.IsNil)+	c.Assert(string(b), qt.Equals, "def")++	count, err := cache.Prune(false)+	c.Assert(err, qt.IsNil)+	c.Assert(count, qt.Equals, 1)+	c.Assert(cache.GetString("MyBundle/i1"), qt.Equals, "")+	c.Assert(cache.GetString("mybundle/i1"), qt.Equals, "def")+}+ func TestPrune(t *testing.T) { 	t.Parallel() htesting/test_helpers.goindex 384695df4..46f6bd9ec 100644@@ -16,6 +16,7 @@ package htesting import ( 	"math/rand" 	"os"+	"path/filepath" 	"regexp" 	"runtime" 	"strconv"@@ -58,6 +59,27 @@ func CreateTempDir(fs afero.Fs, prefix string) (string, func(), error) { 	return tempDir, func() { fs.RemoveAll(tempDir) }, nil } +// IsCaseInsensitiveFs reports whether dir lives on a case-insensitive filesystem+// (e.g. the default on macOS and Windows).+func IsCaseInsensitiveFs(dir string) (bool, error) {+	f, err := os.CreateTemp(dir, "case-*.tmp")+	if err != nil {+		return false, err+	}+	f.Close()+	defer os.Remove(f.Name())++	_, err = os.Stat(filepath.Join(dir, strings.ToUpper(filepath.Base(f.Name()))))+	if err != nil {+		if os.IsNotExist(err) {+			return false, nil+		}+		return false, err+	}++	return true, nil+}+ // BailOut panics with a stack trace after the given duration. Useful for // hanging tests. func BailOut(after time.Duration) {main_test.goindex 12e708dc0..8cea78818 100644@@ -15,6 +15,7 @@ package main  import ( 	"bytes"+	"encoding/base64" 	"encoding/json" 	"fmt" 	"io"@@ -27,6 +28,7 @@ import ( 	"runtime" 	"strconv" 	"strings"+	"sync" 	"testing" 	"time" @@ -78,10 +80,22 @@ func TestMain(m *testing.M) { 	}) } +var isCaseInsensitiveFs = sync.OnceValues(func() (bool, error) {+	return htesting.IsCaseInsensitiveFs(os.TempDir())+})+ var commonTestScriptsParam = testscript.Params{ 	Setup: func(env *testscript.Env) error { 		return testSetupFunc()(env) 	},+	Condition: func(cond string) (bool, error) {+		switch cond {+		case "caseinsensitivefs":+			return isCaseInsensitiveFs()+		default:+			return false, fmt.Errorf("unknown condition %q", cond)+		}+	}, 	Cmds: map[string]func(ts *testscript.TestScript, neg bool, args []string){ 		// log prints to stderr. 		"log": func(ts *testscript.TestScript, neg bool, args []string) {@@ -252,6 +266,34 @@ var commonTestScriptsParam = testscript.Params{ 				ts.Fatalf("failed to create symlink: %v", err) 			} 		},+		// base64decode decodes a base64-encoded file into a binary file.+		"base64decode": func(ts *testscript.TestScript, neg bool, args []string) {+			if len(args) != 2 {+				ts.Fatalf("usage: base64decode src_base64_file dest_binary_file")+			}++			// Resolve paths relative to the test sandbox's current directory+			src := ts.MkAbs(args[0])+			dest := ts.MkAbs(args[1])++			// Read the base64 text+			base64Data, err := os.ReadFile(src)+			if err != nil {+				ts.Fatalf("failed to read base64 file: %v", err)+			}++			// Decode base64 back to raw bytes.+			binaryBytes, err := base64.StdEncoding.DecodeString(strings.TrimSpace(string(base64Data)))+			if err != nil {+				ts.Fatalf("failed to decode base64 data: %v", err)+			}++			// Write the binary file.+			err = os.WriteFile(dest, binaryBytes, 0o644)+			if err != nil {+				ts.Fatalf("failed to write binary file: %v", err)+			}+		},  		// httpget checks that a HTTP resource's body matches (if it compiles as a regexp) or contains all of the strings given as arguments. 		"httpget": func(ts *testscript.TestScript, neg bool, args []string) {testscripts/commands/hugo_gc_mixed_case_cache_dir.txtnew file mode 100644index 000000000..7c7af1373@@ -0,0 +1,38 @@+# In Hugo v0.123 we started lowercasing the content paths, but on case-insensitive+# filesystems existing caches keep their mixed-case dir names (e.g. MyBundle).+# The pruner would then consider those entries unused and remove them on every+# hugo --gc. See issue 15101.++[!caseinsensitivefs] skip++base64decode pixel.png.txt content/MyBundle/pix.png++hugo++stdout 'Processed images │  1 '+tree resources/_gen+stdout 'pix_hu_a354833fd576551d.png'++# Simulate a cache created by an older Hugo version.+mv resources/_gen/images/mybundle resources/_gen/images/MyBundle++hugo --gc+stdout 'Cleaned          │  0 '++tree resources/_gen+stdout 'pix_hu_a354833fd576551d.png'++-- hugo.toml --+disableKinds = ["term", "taxonomy", "home"]+-- layouts/all.html --+All.+-- layouts/page.html --+{{ $pix := .Resources.Get "pix.png" }}+{{ $resized := $pix.Resize "10x10" }}+Resized: {{ $resized.RelPermalink }}+-- content/MyBundle/index.md --+---+title: MyBundle+---+-- pixel.png.txt --+iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg== 

What the agent reported

I fixed the pruner so hugo --gc no longer deletes a cache file the same build just read when the file's on-disk case differs from its cache key. The new regression test fails without the fix and passes with it. I couldn't run it through ./bt-test, because that tool can't build this package here (details under test evidence).

What was wrong: In cache/filecache/filecache_pruner.go, Prune decides whether a file was used by checking the on-disk name against the set of cache keys the build touched, and that check is case-sensitive. On macOS or Windows, MyBundle/cover.jpeg on disk and the key mybundle/cover.jpeg are the same file, but the check treats them as different, so the file is deleted.

What I changed: When the exact name isn't in the set, Prune now looks for keys that match ignoring case. For each one, it keeps the file only if the key resolves to the very same file on disk (c.Fs.Stat(id) plus os.SameFile). The lowercase index of keys is built at most once per prune, and only when some file fails the exact check.

  • macOS / Windows: the key resolves to the mixed-case file, so it is kept.
  • Linux (e.g. an old mixed-case cache copied into CI): the key points to a different file or none, so the stale file is still removed as before.
  • In-memory filesystems: os.SameFile never matches, so nothing changes.

Test: TestPruneCaseInsensitiveFilesystem in cache/filecache/filecache_pruner_test.go runs on a real disk in a temp directory.

  1. A first build creates the cache entries.
  2. The directory is renamed mybundle → MyBundle, as in the report.
  3. On a case-sensitive disk (like this Linux machine), a hard link mybundle/cover.jpeg → MyBundle/cover.jpeg stands in for case-insensitive lookup.
  4. A second build must be a cache hit, then prune runs.
  5. It checks that MyBundle/cover.jpeg still exists. It also checks that a separate stale Other/x.jpeg (key other/x.jpeg) is still deleted on a case-sensitive disk.

Test evidence:

  • ./bt-test ./cache/filecache/ fails before any test runs ("setup failed"): its Go module cache is nearly empty and there is no network. Every result below comes from GOMODCACHE=/bt/cache/go-mod GOPROXY=off GOFLAGS=-mod=mod go test ....
  • Without the fix: the new test fails with "in-use cache entry …/MyBundle/cover.jpeg was pruned … no such file or directory".
  • With the fix: all of ./cache/filecache/ passes, including the new test, TestPrune and TestPruneShouldPreserveEmptyCacheRoots. TestPruneImages and TestFileCacheConcurrent are skipped by the repo itself.
  • Adjacent packages: ./cache/... passes. In ./resources/images, four tests fail (TestImagesGoldenProcessMisc, TestImagesGoldenFiltersMask, TestImagesGoldenMethods, TestImagesGoldenProcessWebP). They fail the same way with my change stashed, so they are not caused by it.

The reviewer read the final diff, found no blocking issues, and confirmed that nothing unrelated changed. The changes are uncommitted.

Requirements:

  1. --gc must never delete an entry the same build read — done; the new test covers it.
  2. Compare case-insensitively on case-insensitive filesystems (the report's suggestion) — done. Instead of guessing whether the filesystem is case-insensitive, it checks that the matching key is the same physical file.
  3. The reproduction scenario (a MyBundle/ cache left by an older Hugo) — covered by the test. The endless rebuild-and-delete cycle also stops, because the file is no longer deleted.
  4. Renaming entries to the key's case to self-heal old caches — not done. The report offered it only as an optional extra; renaming directories that differ only in case on case-insensitive filesystems needs a two-step rename and adds risk. With the fix, old caches stay valid and simply keep their mixed-case directory names.
  5. Keep deleting truly stale files on case-sensitive filesystems — kept; the Other/x.jpeg check in the test covers it.

The reviewer noted a few edge cases outside this report:

  • Unicode forms: filenames that differ in Unicode form (NFC vs NFD, e.g. on HFS+) rather than case are still pruned, same as before this change.
  • Hard links on Linux: a stale mixed-case file that happens to be a hard link to an in-use entry would now be kept. That uses no extra disk space.
  • Symlinks: a cache file that is a symlink still doesn't match its key, same as before.