Skip to content

Commit

Permalink
fedora-ostree-pruner: generic prune for deleted refs
Browse files Browse the repository at this point in the history
Just delete the ref first and then we'll do a generic prune for
unreachable objects after looping through all the refs in the repo.

This also means if more than one refs points to a commit we won't delete
it like we were doing with the `ostree prune --delete-commit=$commit`
approach.
  • Loading branch information
dustymabe committed Nov 11, 2021
1 parent 1f2400d commit 661f8fe
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions fedora-ostree-pruner/fedora-ostree-pruner
Original file line number Diff line number Diff line change
Expand Up @@ -129,29 +129,15 @@ def delete_ref_in_repo(ref: str, repo: str, test: bool):
logger.info('Skipping delete because of test mode')
return

# Grab the commit hash from the ref
cmd = ['ostree', 'rev-parse', '--repo', repo, ref]
cp = runcmd(cmd)
commit = cp.stdout.decode('utf-8').strip()

# Prune all but the last commit
cmd = ['ostree', 'prune', '--repo', repo,
'--only-branch', ref, '--refs-only',
'--depth=0']
runcmd(cmd, capture_output=False)

# Delete the ref
# Delete the ref. We don't worry about pruning here as we'll
# run a generic prune for unreachable objects afterwards
cmd = ['ostree', 'refs', '--repo', repo, '--delete', ref]
runcmd(cmd)

# Update the summary file since we deleted a ref
cmd = ['ostree', 'summary', '--repo', repo, '-u']
runcmd(cmd)

# Prune the last commit
cmd = ['ostree', 'prune', '--repo', repo, f'--delete-commit={commit}']
runcmd(cmd, capture_output=False)


def prune_compose_repo(test=False):
# prune the compose repo
Expand Down Expand Up @@ -185,6 +171,7 @@ def prune_prod_repo(test=False):
continue

# prune each branch in the policy with specified value
deleted_a_ref = False
for ref,policy in PROD_REF_POLICIES.items():

# Skip if there is no ref in the repo for this policy
Expand All @@ -198,6 +185,7 @@ def prune_prod_repo(test=False):

if policy == 'delete':
delete_ref_in_repo(ref, OSTREEPRODREPO, test)
deleted_a_ref = True
continue

prunearg = pruning_policy_to_args(policy)
Expand All @@ -209,6 +197,17 @@ def prune_prod_repo(test=False):
cmd.append('--no-prune')
runcmd(cmd)

# If we deleted a ref from the repo then we'll just run a generic
# prune to delete any objects in the repo that aren't reachable
# via a ref. This should save some time since we only call ostree
# prune once, versus for every ref we deleted.
if deleted_a_ref:
cmd = ['ostree', 'prune', '--repo', OSTREEPRODREPO, '--refs-only']
if test:
cmd.append('--no-prune')
runcmd(cmd, capture_output=False)


# XXX this function should not be used yet as there are a few
# bugs to work out:
# https://github.com/ostreedev/ostree/issues/1479
Expand Down

0 comments on commit 661f8fe

Please sign in to comment.