summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Maat <tm@tlater.net>2018-03-23 17:26:32 +0000
committerJames Ennis <james.ennis@codethink.com>2018-06-06 09:00:27 +0100
commitfcea521334e766d1f40a489ddf09ecf8cb9a1014 (patch)
treec1f725584e183d1d79fc4d9ca6e1e568c9f69d38
parent1d694b28297e86b53dff07e49abd135f5c7709ed (diff)
downloadbuildstream-fcea521334e766d1f40a489ddf09ecf8cb9a1014.tar.gz
_ostree.py: Reintroduce remove()
-rw-r--r--buildstream/_ostree.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/buildstream/_ostree.py b/buildstream/_ostree.py
index dfa7567de..246b54f51 100644
--- a/buildstream/_ostree.py
+++ b/buildstream/_ostree.py
@@ -225,6 +225,42 @@ def exists(repo, ref):
return has_object
+# remove():
+#
+# Removes the given commit or symbolic ref from the repo.
+#
+# Args:
+# repo (OSTree.Repo): The repo
+# ref (str): A commit checksum or symbolic ref
+# defer_prune (bool): Whether to defer pruning to the caller. NOTE:
+# The space won't be freed until you manually
+# call repo.prune.
+#
+# Returns:
+# (int|None) The amount of space pruned from the repository in
+# Bytes, or None if defer_prune is True
+#
+def remove(repo, ref, *, defer_prune=False):
+
+ # Get the commit checksum, this will:
+ #
+ # o Return a commit checksum if ref is a symbolic branch
+ # o Return the same commit checksum if ref is a valid commit checksum
+ # o Return None if the ostree repo doesnt know this ref.
+ #
+ check = checksum(repo, ref)
+ if check is None:
+ raise OSTreeError("Could not find artifact for ref '{}'".format(ref))
+
+ repo.set_ref_immediate(None, ref, None)
+
+ if not defer_prune:
+ _, _, _, pruned = repo.prune(OSTree.RepoPruneFlags.REFS_ONLY, -1)
+ return pruned
+
+ return None
+
+
# checksum():
#
# Returns the commit checksum for a given symbolic ref,