diff --git a/skills/kvb-org-organize/scripts/watch.py b/skills/kvb-org-organize/scripts/watch.py index b308673..caee087 100755 --- a/skills/kvb-org-organize/scripts/watch.py +++ b/skills/kvb-org-organize/scripts/watch.py @@ -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 diff --git a/tests/test_watch.py b/tests/test_watch.py index d75f636..136a58d 100644 --- a/tests/test_watch.py +++ b/tests/test_watch.py @@ -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: