diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h index 80dc0877..7edc635d 100644 --- a/src/libostree/ostree-repo.h +++ b/src/libostree/ostree-repo.h @@ -149,6 +149,12 @@ gboolean ostree_repo_load_variant (OstreeRepo *self, GVariant **out_variant, GError **error); +gboolean ostree_repo_load_variant_if_exists (OstreeRepo *self, + OstreeObjectType expected_type, + const char *sha256, + GVariant **out_variant, + GError **error); + gboolean ostree_repo_load_pack_index (OstreeRepo *self, const char *pack_checksum, gboolean is_meta, diff --git a/src/libostree/ostree-traverse.c b/src/libostree/ostree-traverse.c index 2cc4de5c..b4a403a9 100644 --- a/src/libostree/ostree-traverse.c +++ b/src/libostree/ostree-traverse.c @@ -44,7 +44,7 @@ traverse_dirtree_internal (OstreeRepo *repo, { gboolean ret = FALSE; int n, i; - ot_lvariant GVariant *key; + ot_lvariant GVariant *key = NULL; ot_lvariant GVariant *tree = NULL; ot_lvariant GVariant *files_variant = NULL; ot_lvariant GVariant *dirs_variant = NULL; @@ -60,9 +60,12 @@ traverse_dirtree_internal (OstreeRepo *repo, goto out; } - if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_DIR_TREE, dirtree_checksum, &tree, error)) + if (!ostree_repo_load_variant_if_exists (repo, OSTREE_OBJECT_TYPE_DIR_TREE, dirtree_checksum, &tree, error)) goto out; + if (!tree) + return TRUE; + key = ostree_object_name_serialize (dirtree_checksum, OSTREE_OBJECT_TYPE_DIR_TREE); if (!g_hash_table_lookup (inout_reachable, key)) { @@ -126,6 +129,12 @@ ostree_traverse_dirtree (OstreeRepo *repo, inout_reachable, cancellable, error); } +/** + * ostree_traverse_commit: + * + * Add to @inout_reachable all objects reachable from + * @commit_checksum, traversing @maxdepth parent commits. + */ gboolean ostree_traverse_commit (OstreeRepo *repo, const char *commit_checksum, @@ -147,8 +156,14 @@ ostree_traverse_commit (OstreeRepo *repo, ot_lvariant GVariant *commit = NULL; /* PARSE OSTREE_SERIALIZED_COMMIT_VARIANT */ - if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, commit_checksum, &commit, error)) + if (!ostree_repo_load_variant_if_exists (repo, OSTREE_OBJECT_TYPE_COMMIT, commit_checksum, &commit, error)) goto out; + + /* Just return if the parent isn't found; we do expect most + * people to have partial repositories. + */ + if (!commit) + break; key = ostree_object_name_serialize (commit_checksum, OSTREE_OBJECT_TYPE_COMMIT); g_hash_table_replace (inout_reachable, key, key); diff --git a/src/ostree/ot-builtin-prune.c b/src/ostree/ot-builtin-prune.c index a307dee5..51a29924 100644 --- a/src/ostree/ot-builtin-prune.c +++ b/src/ostree/ot-builtin-prune.c @@ -93,7 +93,8 @@ prune_loose_object (OtPruneData *data, } else { - g_print ("Unreachable: %s.%s\n", checksum, ostree_object_type_to_string (objtype)); + if (verbose) + g_print ("Unreachable: %s.%s\n", checksum, ostree_object_type_to_string (objtype)); } data->n_unreachable++; }