fix(kvb-org-organize): skip a missing cache root in the cache trim
cache_files walked every cache_dirs entry with os.fwalk, which raises FileNotFoundError for a folder that does not exist (~/.cache/ms-playwright on this host), so cleanup --caches crashed and trim_caches never ran at disk stage warn. A root that cannot be walked is now skipped and the other roots are still trimmed. 🎯 Fix: 95 % 💥 Break: 2 % 💸 Cost: 100 % ⏱️ Time: 100 % 🛡️ Security: 100 % 🏆 Score: 93 🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c3ab6b7e18
commit
8f942ff071
2 files changed
+23
-10
No files matched your search
@@ -1047,16 +1047,19 @@ def cache_files(dirs: list[str]) -> list[tuple[float, int, str, str]]:
|
||||
files = []
|
||||
seen: set[tuple[int, int]] = set()
|
||||
for root in map(os.path.expanduser, dirs):
|
||||
for base, _, names, fd in os.fwalk(root, follow_symlinks=False):
|
||||
for name in names:
|
||||
try:
|
||||
st = os.stat(name, dir_fd=fd, follow_symlinks=False)
|
||||
except OSError:
|
||||
continue
|
||||
if (st.st_dev, st.st_ino) in seen:
|
||||
continue
|
||||
seen.add((st.st_dev, st.st_ino))
|
||||
files.append((st.st_atime, st.st_blocks * 512, os.path.join(base, name), root))
|
||||
try:
|
||||
for base, _, names, fd in os.fwalk(root, follow_symlinks=False):
|
||||
for name in names:
|
||||
try:
|
||||
st = os.stat(name, dir_fd=fd, follow_symlinks=False)
|
||||
except OSError:
|
||||
continue
|
||||
if (st.st_dev, st.st_ino) in seen:
|
||||
continue
|
||||
seen.add((st.st_dev, st.st_ino))
|
||||
files.append((st.st_atime, st.st_blocks * 512, os.path.join(base, name), root))
|
||||
except OSError:
|
||||
continue
|
||||
return files
|
||||
|
||||
|
||||
|
||||
@@ -637,6 +637,16 @@ class TestWatchCommands(unittest.TestCase):
|
||||
kept = self.base / ".local" / "state" / "agents-council" / "queue-history.jsonl"
|
||||
self.assertNotIn("outside", kept.read_text(encoding="utf-8") if kept.exists() else "")
|
||||
|
||||
def test_cache_trim_skips_a_missing_cache_root_and_trims_the_others(self):
|
||||
watch = _load()
|
||||
old = self.cache / "old"
|
||||
old.write_bytes(b"x" * 4096)
|
||||
os.utime(old, (0, 0))
|
||||
self.cfg["cache_dirs"] = [str(self.base / "missing"), str(old), str(self.cache)]
|
||||
self.cfg["cache_budget_percent"] = 0
|
||||
watch.trim_caches(self.cfg)
|
||||
self.assertFalse(old.exists())
|
||||
|
||||
def test_cache_trim_counts_the_blocks_a_sparse_file_holds(self):
|
||||
watch = _load()
|
||||
with (self.cache / "sparse").open("wb") as handle:
|
||||
|
||||
Reference in new issue
Block a user