From bed6c800bd3c97624d76b4de60c1bb98bb08d07f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Tue, 10 Jul 2018 16:15:27 +0200 Subject: _artifactcache/cascache.py: Add list_artifacts() method --- buildstream/_artifactcache/cascache.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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. -- cgit v1.2.1