Skip to content

Commit 760c9b0

Browse files
committed
CachedAddon: append location-based IDs to cache dirs
In order to force separate repos using overlapping IDs to use different caches. Note this will force cache rebuilds for all repos using the old cache dir paths. Fixes #321.
1 parent aede5a5 commit 760c9b0

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/pkgcheck/addons/caches.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import shutil
88
from collections import UserDict
99
from dataclasses import dataclass
10+
from hashlib import blake2b
1011
from operator import attrgetter
1112

1213
from snakeoil import klass
@@ -68,10 +69,14 @@ def update_cache(self, repo=None, force=False):
6869
raise NotImplementedError(self.update_cache)
6970

7071
def cache_file(self, repo):
71-
"""Return the cache file for a given repository."""
72-
return pjoin(
73-
self.options.cache_dir, 'repos',
74-
repo.repo_id.lstrip(os.sep), self.cache.file)
72+
"""Return the cache file for a given repository.
73+
74+
A unique token using the repo's location is used so separate repos
75+
using the same identifier don't use the same cache file.
76+
"""
77+
token = blake2b(repo.location.encode()).hexdigest()[:10]
78+
dirname = f'{repo.repo_id.lstrip(os.sep)}-{token}'
79+
return pjoin(self.options.cache_dir, 'repos', dirname, self.cache.file)
7580

7681
def load_cache(self, path, fallback=None):
7782
cache = fallback

tests/scripts/test_pkgcheck_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_cache_profiles(self, capsys):
3232
out, err = capsys.readouterr()
3333
assert not err
3434
out = out.strip().splitlines()
35-
assert out[-1] == 'standalone'
35+
assert out[-1].startswith('standalone-')
3636
assert excinfo.value.code == 0
3737

3838
# pretend to remove it

0 commit comments

Comments
 (0)