Skip to content

Commit

Permalink
lib/repo: Do account for size with prune --no-prune
Browse files Browse the repository at this point in the history
I think this got changed in a refactor.  We definitely want
to total up the amount of space that *would* be freed even
with `--no-prune` AKA `OSTREE_REPO_PRUNE_FLAGS_NO_PRUNE`.

It's actually a bit terrifying this is apparently the first test case for
the `--no-prune` option...

Closes: #1480

Closes: #1483
Approved by: jlebon
  • Loading branch information
cgwalters authored and rh-atomic-bot committed Mar 5, 2018
1 parent 1214395 commit 733c049
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/libostree/ostree-repo-prune.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,31 @@ maybe_prune_loose_object (OtPruneData *data,

if (!g_hash_table_lookup_extended (data->reachable, key, NULL, NULL))
{
guint64 storage_size = 0;

g_debug ("Pruning unneeded object %s.%s", checksum,
ostree_object_type_to_string (objtype));

if (!ostree_repo_query_object_storage_size (data->repo, objtype, checksum,
&storage_size, cancellable, error))
return FALSE;

data->freed_bytes += storage_size;

if (!(flags & OSTREE_REPO_PRUNE_FLAGS_NO_PRUNE))
{
guint64 storage_size = 0;

if (objtype == OSTREE_OBJECT_TYPE_COMMIT)
{
if (!ostree_repo_mark_commit_partial (data->repo, checksum, FALSE, error))
return FALSE;
}

if (!ostree_repo_query_object_storage_size (data->repo, objtype, checksum,
&storage_size, cancellable, error))
return FALSE;

if (!ostree_repo_delete_object (data->repo, objtype, checksum,
cancellable, error))
return FALSE;

data->freed_bytes += storage_size;
}

if (OSTREE_OBJECT_TYPE_IS_META (objtype))
data->n_unreachable_meta++;
else
Expand Down
7 changes: 7 additions & 0 deletions tests/test-prune.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ assert_repo_has_n_commits() {
assert_streq "$(find ${repo}/objects -name '*.commit' | wc -l)" "${count}"
}

# Test --no-prune
objectcount_orig=$(find repo/objects | wc -l)
${CMD_PREFIX} ostree prune --repo=repo --refs-only --depth=0 --no-prune | tee noprune.txt
assert_file_has_content noprune.txt 'Would delete: [1-9][0-9]* objects, freeing [1-9][0-9]*'
objectcount_new=$(find repo/objects | wc -l)
assert_streq "${objectcount_orig}" "${objectcount_new}"

${CMD_PREFIX} ostree prune --repo=repo --refs-only --depth=2 -v
assert_repo_has_n_commits repo 3
find repo/objects -name '*.tombstone-commit' | wc -l > tombstonecommitcount
Expand Down

0 comments on commit 733c049

Please sign in to comment.