mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-08-12 22:28:06 +00:00
fix(cache): count swept temp files as scanned
files_scanned only counted completed .json files, so a sweep that removed orphans reported more deleted than it had looked at -- the summary line renders "<deleted>/<scanned>", which came out as "76/1". Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Udr6MfaFLUPhX5Fgo67Jf5
This commit is contained in:
co-authored by
Claude Opus 5
parent
e03fbfe7b1
commit
e2d865d41b
Vendored
+4
@@ -423,6 +423,10 @@ class DiskCache:
|
|||||||
# directory, the oldest six months old.
|
# directory, the oldest six months old.
|
||||||
stats['orphan_temp_files_deleted'] = 0
|
stats['orphan_temp_files_deleted'] = 0
|
||||||
for filename in (f for f in entries if self._is_orphaned_temp(f)):
|
for filename in (f for f in entries if self._is_orphaned_temp(f)):
|
||||||
|
# Counted as scanned like any other candidate, so files_deleted
|
||||||
|
# can never exceed files_scanned and the summary line reads
|
||||||
|
# honestly ("77/8864", not "77/0").
|
||||||
|
stats['files_scanned'] += 1
|
||||||
path = os.path.join(self.cache_dir, filename)
|
path = os.path.join(self.cache_dir, filename)
|
||||||
try:
|
try:
|
||||||
# An in-flight write lives for milliseconds, so anything
|
# An in-flight write lives for milliseconds, so anything
|
||||||
|
|||||||
@@ -152,6 +152,19 @@ class TestTheSweep:
|
|||||||
assert stats['orphan_temp_files_deleted'] == 76
|
assert stats['orphan_temp_files_deleted'] == 76
|
||||||
assert keep.exists()
|
assert keep.exists()
|
||||||
assert not list(tmp_path.glob('.sched_*'))
|
assert not list(tmp_path.glob('.sched_*'))
|
||||||
|
# The summary line is "<deleted>/<scanned>", so an orphan that is
|
||||||
|
# deleted but never counted as scanned renders as "76/1".
|
||||||
|
assert stats['files_scanned'] == 77
|
||||||
|
assert stats['files_deleted'] <= stats['files_scanned']
|
||||||
|
|
||||||
|
def test_deleted_never_exceeds_scanned(self, cache, tmp_path):
|
||||||
|
p = _write(tmp_path, '.only.json.a1b2c3d4')
|
||||||
|
_age(p, _ORPHAN_TEMP_MAX_AGE_SECONDS + 60)
|
||||||
|
|
||||||
|
stats = cache.cleanup_expired_files(FakeStrategy(), POLICIES)
|
||||||
|
|
||||||
|
assert stats['files_deleted'] == 1
|
||||||
|
assert stats['files_scanned'] == 1
|
||||||
|
|
||||||
def test_a_missing_file_mid_sweep_is_not_an_error(self, cache, tmp_path):
|
def test_a_missing_file_mid_sweep_is_not_an_error(self, cache, tmp_path):
|
||||||
p = _write(tmp_path, '.weather.json.a1b2c3d4')
|
p = _write(tmp_path, '.weather.json.a1b2c3d4')
|
||||||
|
|||||||
Reference in New Issue
Block a user