Skip to content

Tag cache directories with CACHEDIR.TAG - #373

Open
hikmetba-bit wants to merge 1 commit into
grantjenks:masterfrom
hikmetba-bit:feature/cachedir-tag-352
Open

hikmetba-bit wants to merge 1 commit into
grantjenks:masterfrom
hikmetba-bit:feature/cachedir-tag-352

Conversation

@hikmetba-bit

Copy link
Copy Markdown

Summary

Fixes #352.

Writes a standard CACHEDIR.TAG file into each Cache directory on init, so backup and archiving tools that understand the convention (rsync --cvs-exclude, tar --exclude-caches-all, some backup GUIs, etc.) can skip disposable cache data automatically.

FanoutCache shards each get one too, since every shard is itself a Cache instance created in the same __init__, so no separate change was needed there.

Details

  • The write happens right after the directory-creation step, using exclusive-create ('xb') so it's a no-op if the tag already exists, and any OSError (e.g. a read-only cache directory) is swallowed — this is a best-effort convenience file, not something that should ever break cache initialization.
  • Cache.check()'s "unknown file" scan needed a matching change: it already special-cases the sqlite DBNAME files so they aren't flagged/removed as untracked files, and CACHEDIR.TAG needed the same treatment, otherwise check(fix=True) would delete it.

Test plan

  • Added test_cachedir_tag in tests/test_core.py: asserts the tag file exists with the correct standard signature after Cache() init, and that cache.check(fix=True) neither warns about it nor removes it.
  • Ran pytest tests/test_core.py tests/test_fanout.py: 130 passed, no regressions.

🤖 Generated with Claude Code

Fixes grantjenks#352.

Writes a standard CACHEDIR.TAG file (https://bford.info/cachedir/)
into each Cache directory on init, so backup tools (rsync --cvs-exclude,
tar --exclude-caches, etc.) can skip disposable cache data. FanoutCache
shards get one too, since each shard is itself a Cache instance.

The write is best-effort (an OSError, e.g. a read-only directory, is
swallowed) and idempotent ('xb' exclusive-create, skipped if the tag
already exists).

Cache.check()'s "unknown file" scan also needed to ignore the tag file,
the same way it already ignores the sqlite DBNAME files, otherwise
check(fix=True) would delete it as an untracked file.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CACHEDIR.TAG

1 participant