diff options
author | Jürg Billeter <j@bitron.ch> | 2018-07-10 16:15:27 +0200 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2018-07-17 07:56:40 +0200 |
commit | bed6c800bd3c97624d76b4de60c1bb98bb08d07f (patch) | |
tree | 2c6f2141a51506490741cacef9ca30d347fda7c3 /buildstream | |
parent | 687b9a8b5860d63fd893f7973009483870fb03eb (diff) | |
download | buildstream-bed6c800bd3c97624d76b4de60c1bb98bb08d07f.tar.gz |
_artifactcache/cascache.py: Add list_artifacts() method
Diffstat (limited to 'buildstream')
-rw-r--r-- | buildstream/_artifactcache/cascache.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/buildstream/_artifactcache/cascache.py b/buildstream/_artifactcache/cascache.py index 1668c88b3..efedc7696 100644 --- a/buildstream/_artifactcache/cascache.py +++ b/buildstream/_artifactcache/cascache.py @@ -222,6 +222,31 @@ class CASCache(ArtifactCache): except FileNotFoundError as e: raise ArtifactError("Attempt to access unavailable artifact: {}".format(e)) from e + # list_artifacts(): + # + # List cached artifacts in Least Recently Modified (LRM) order. + # + # Returns: + # (list) - A list of refs in LRM order + # + def list_artifacts(self): + # string of: /path/to/repo/refs/heads + ref_heads = os.path.join(self.casdir, 'refs', 'heads') + + refs = [] + mtimes = [] + + for root, _, files in os.walk(ref_heads): + for filename in files: + ref_path = os.path.join(root, filename) + refs.append(os.path.relpath(ref_path, ref_heads)) + # Obtain the mtime (the time a file was last modified) + mtimes.append(os.path.getmtime(ref_path)) + + # NOTE: Sorted will sort from earliest to latest, thus the + # first element of this list will be the file modified earliest. + return [ref for _, ref in sorted(zip(mtimes, refs))] + # remove(): # # Removes the given symbolic ref from the repo. |