summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2018-07-10 16:15:07 +0200
committerJürg Billeter <j@bitron.ch>2018-07-17 07:56:40 +0200
commit687b9a8b5860d63fd893f7973009483870fb03eb (patch)
tree42866cbe4fafa4a2d17692c15e82047a98d849bd
parenta3bdfc1882b576fbe205bd92fb75978669f4cc9d (diff)
downloadbuildstream-687b9a8b5860d63fd893f7973009483870fb03eb.tar.gz
_artifactcache/cascache.py: Add remove() method
-rw-r--r--buildstream/_artifactcache/cascache.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/buildstream/_artifactcache/cascache.py b/buildstream/_artifactcache/cascache.py
index d1d975c8f..1668c88b3 100644
--- a/buildstream/_artifactcache/cascache.py
+++ b/buildstream/_artifactcache/cascache.py
@@ -222,6 +222,34 @@ class CASCache(ArtifactCache):
except FileNotFoundError as e:
raise ArtifactError("Attempt to access unavailable artifact: {}".format(e)) from e
+ # remove():
+ #
+ # Removes the given symbolic ref from the repo.
+ #
+ # Args:
+ # ref (str): A symbolic ref
+ # defer_prune (bool): Whether to defer pruning to the caller. NOTE:
+ # The space won't be freed until you manually
+ # call prune.
+ #
+ # Returns:
+ # (int|None) The amount of space pruned from the repository in
+ # Bytes, or None if defer_prune is True
+ #
+ def remove(self, ref, *, defer_prune=False):
+
+ refpath = self._refpath(ref)
+ if not os.path.exists(refpath):
+ raise ArtifactError("Could not find artifact for ref '{}'".format(ref))
+
+ os.unlink(refpath)
+
+ if not defer_prune:
+ pruned = self.prune()
+ return pruned
+
+ return None
+
# prune():
#
# Prune unreachable objects from the repo.