summaryrefslogtreecommitdiff
path: root/morphlib/localartifactcache.py
diff options
context:
space:
mode:
Diffstat (limited to 'morphlib/localartifactcache.py')
-rw-r--r--morphlib/localartifactcache.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/morphlib/localartifactcache.py b/morphlib/localartifactcache.py
index e6695c4e..1b834a32 100644
--- a/morphlib/localartifactcache.py
+++ b/morphlib/localartifactcache.py
@@ -129,11 +129,21 @@ class LocalArtifactCache(object):
returns a [(cache_key, set(artifacts), last_used)]
'''
+ def is_artifact(filename):
+ # This is just enough to avoid crashes from random unpacked
+ # directory trees and temporary files in the cachedir. A
+ # better mechanism is needed. It's not simple to tell
+ # OSFS.walkfiles() to do a non-recursive walk, sadly.
+ return '.' in filename and '/' not in filename
+
CacheInfo = collections.namedtuple('CacheInfo', ('artifacts', 'mtime'))
contents = collections.defaultdict(lambda: CacheInfo(set(), 0))
for filename in self.cachefs.walkfiles():
- cachekey = filename[:63]
- artifact = filename[65:]
+ # filenames are returned with a preceeding /.
+ filename = filename[1:]
+ if not is_artifact(filename): # pragma: no cover
+ continue
+ cachekey, artifact = filename.split('.', 1)
artifacts, max_mtime = contents[cachekey]
artifacts.add(artifact)
art_info = self.cachefs.getinfo(filename)
@@ -146,5 +156,5 @@ class LocalArtifactCache(object):
def remove(self, cachekey):
'''Remove all artifacts associated with the given cachekey.'''
for filename in (x for x in self.cachefs.walkfiles()
- if x.startswith(cachekey)):
+ if x[1:].startswith(cachekey)):
self.cachefs.remove(filename)