You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:41:56 UTC
[buildstream] 01/09: _ostree.py: Reintroduce remove()
This is an automated email from the ASF dual-hosted git repository.
not-in-ldap pushed a commit to branch jennis/alternative_remote_expiry
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit fcea521334e766d1f40a489ddf09ecf8cb9a1014
Author: Tristan Maat <tm...@tlater.net>
AuthorDate: Fri Mar 23 17:26:32 2018 +0000
_ostree.py: Reintroduce remove()
---
buildstream/_ostree.py | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/buildstream/_ostree.py b/buildstream/_ostree.py
index dfa7567..246b54f 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,