diff options
author | Tristan Maat <tm@tlater.net> | 2018-03-23 17:26:32 +0000 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-06-07 16:35:51 -0400 |
commit | 4632cb039d543d78a9a8956c605fa3ed40f3f035 (patch) | |
tree | 331b7c0ad4f46bc0cbbb83a1f8c0afdba789f74b /buildstream | |
parent | 9c65b908b8dadd820bb6e0352e15a34b33137e2c (diff) | |
download | buildstream-4632cb039d543d78a9a8956c605fa3ed40f3f035.tar.gz |
_ostree.py: Reintroduce remove()
Diffstat (limited to 'buildstream')
-rw-r--r-- | buildstream/_ostree.py | 36 |
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, |