cache_key_id_file
Records which cache key encrypted the caches, so no other key is used.
The first time a cache is encrypted, the key's public id is written to a file in the cache directory. Every later key is checked against it: a machine whose key has changed (a second key, or a key restored from the wrong backup) is refused, rather than left to start fresh encrypted caches beside the old ones. The file is created once and never replaced; a file that can't be read refuses every key.
Module
Functions
check_key_id
def check_key_id(cache_dir: Path, key: CacheKey) ‑> None:Checks key against the key id recorded in cache_dir.
Arguments
cache_dir: The directory holding the caches.key: The cache key about to be used.
Raises
CacheKeyMismatchError: If a different key id is recorded, or the record can't be read or doesn't hold a key id. Nothing is raised when no key id has been recorded yet.
record_key_id
def record_key_id(cache_dir: Path, key: CacheKey) ‑> None:Records key's id in cache_dir, unless a key id is already recorded.
The id is written to a temporary file that is then hard-linked into place, which fails if the record already exists. So a crash never leaves a partial record, and of two processes recording at once, one wins and the other is checked against it.
Arguments
cache_dir: The directory holding the caches; created if missing.key: The cache key the caches are being encrypted with.
Raises
CacheKeyMismatchError: If a key id is already recorded and it isn'tkey's, or the existing record can't be read.