fix: keep the cache usable when a path is both

This commit is contained in:
Abdessamad Derraz committed 2026-08-10 19:10:26 +02:00
1 parent 1ac569b98e
commit 5330ed1950
5 files changed
+33 -13

No files matched your search

+11 -2
View File
@@ -213,8 +213,17 @@ def cache_path(cache_dir: str, repo: Repo, sha: str, path: str) -> Path:
def write_cache(target: Path, text: str) -> None:
"""Atomic write: unique scratch in the target directory, then replace."""
target.parent.mkdir(parents=True, exist_ok=True)
"""Atomic write: unique scratch in the target directory, then replace.
A profile can cite both a directory and files inside it, and the first
citation caches `vice/data/C64DTV` as a file, which then blocks the
directory the second one needs. The cache is derived data, so a collision
skips the write rather than failing the read.
"""
try:
target.parent.mkdir(parents=True, exist_ok=True)
except (FileExistsError, NotADirectoryError):
return
fd, scratch = tempfile.mkstemp(dir=str(target.parent), suffix=".part")
try:
with os.fdopen(fd, "w", encoding="utf-8") as fh: