From: Philip Withnall Date: Fri, 9 Jun 2017 17:45:39 +0000 (+0100) Subject: ostree/builtins: Add support for collection–refs to a few utilities X-Git-Tag: archive/raspbian/2022.1-3+rpi1~1^2~4^2~35^2~48 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=3dd4848c9606f3e8d5e4c974f16be5e910769a5f;p=ostree.git ostree/builtins: Add support for collection–refs to a few utilities These utilities were not needed for the initial port to support OstreeCollectionRef, so have been delayed a bit and, in some cases, left as FIXME comments for follow up later. Signed-off-by: Philip Withnall Closes: #924 Approved by: cgwalters --- diff --git a/src/ostree/ot-builtin-fsck.c b/src/ostree/ot-builtin-fsck.c index 936bdce4..66f5536d 100644 --- a/src/ostree/ot-builtin-fsck.c +++ b/src/ostree/ot-builtin-fsck.c @@ -241,6 +241,28 @@ ostree_builtin_fsck (int argc, char **argv, GCancellable *cancellable, GError ** return glnx_prefix_error (error, "Loading commit for ref %s", refname); } +#ifdef OSTREE_ENABLE_EXPERIMENTAL_API + if (!opt_quiet) + g_print ("Validating refs in collections...\n"); + + g_autoptr(GHashTable) all_collection_refs = NULL; /* (element-type OstreeCollectionRef utf8) */ + if (!ostree_repo_list_collection_refs (repo, NULL, &all_collection_refs, + cancellable, error)) + return FALSE; + + g_hash_table_iter_init (&hash_iter, all_collection_refs); + while (g_hash_table_iter_next (&hash_iter, &key, &value)) + { + const OstreeCollectionRef *ref = key; + const char *checksum = value; + g_autoptr(GVariant) commit = NULL; + if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, + checksum, &commit, error)) + return glnx_prefix_error (error, "Loading commit for ref (%s, %s)", + ref->collection_id, ref->ref_name); + } +#endif /* OSTREE_ENABLE_EXPERIMENTAL_API */ + if (!opt_quiet) g_print ("Enumerating objects...\n"); diff --git a/src/ostree/ot-builtin-prune.c b/src/ostree/ot-builtin-prune.c index 853c051f..8c595b73 100644 --- a/src/ostree/ot-builtin-prune.c +++ b/src/ostree/ot-builtin-prune.c @@ -50,11 +50,15 @@ static GOptionEntry options[] = { static gboolean delete_commit (OstreeRepo *repo, const char *commit_to_delete, GCancellable *cancellable, GError **error) { - g_autoptr(GHashTable) refs = NULL; + g_autoptr(GHashTable) refs = NULL; /* (element-type utf8 utf8) */ +#ifdef OSTREE_ENABLE_EXPERIMENTAL_API + g_autoptr(GHashTable) collection_refs = NULL; /* (element-type OstreeCollectionRef utf8) */ +#endif /* OSTREE_ENABLE_EXPERIMENTAL_API */ GHashTableIter hashiter; gpointer hashkey, hashvalue; gboolean ret = FALSE; + /* Check refs which are not in a collection. */ if (!ostree_repo_list_refs (repo, NULL, &refs, cancellable, error)) goto out; @@ -71,6 +75,26 @@ delete_commit (OstreeRepo *repo, const char *commit_to_delete, GCancellable *can } } +#ifdef OSTREE_ENABLE_EXPERIMENTAL_API + /* And check refs which *are* in a collection. */ + if (!ostree_repo_list_collection_refs (repo, NULL, &collection_refs, cancellable, error)) + goto out; + + g_hash_table_iter_init (&hashiter, collection_refs); + while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue)) + { + const OstreeCollectionRef *ref = hashkey; + const char *commit = hashvalue; + if (g_strcmp0 (commit_to_delete, commit) == 0) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, + "Commit '%s' is referenced by (%s, %s)", + commit_to_delete, ref->collection_id, ref->ref_name); + goto out; + } + } +#endif /* OSTREE_ENABLE_EXPERIMENTAL_API */ + if (!ot_enable_tombstone_commits (repo, error)) goto out; @@ -249,6 +273,7 @@ ostree_builtin_prune (int argc, char **argv, GCancellable *cancellable, GError * } /* We start from the refs */ + /* FIXME: Do we also want to look at ostree_repo_list_collection_refs()? */ if (!ostree_repo_list_refs (repo, NULL, &all_refs, cancellable, error)) return FALSE; diff --git a/src/ostree/ot-builtin-pull-local.c b/src/ostree/ot-builtin-pull-local.c index b19a4c6a..66e189bc 100644 --- a/src/ostree/ot-builtin-pull-local.c +++ b/src/ostree/ot-builtin-pull-local.c @@ -111,6 +111,8 @@ ostree_builtin_pull_local (int argc, char **argv, GCancellable *cancellable, GEr if (!ostree_repo_open (src_repo, cancellable, error)) goto out; + /* FIXME: This should grow support for pulling refs from refs/mirrors on + * a local repository, using ostree_repo_list_collection_refs(). */ if (!ostree_repo_list_refs (src_repo, NULL, &refs_to_clone, cancellable, error)) goto out; diff --git a/src/ostree/ot-builtin-reset.c b/src/ostree/ot-builtin-reset.c index cab579ae..344d692c 100644 --- a/src/ostree/ot-builtin-reset.c +++ b/src/ostree/ot-builtin-reset.c @@ -45,6 +45,7 @@ ostree_builtin_reset (int argc, const char *target = NULL; g_autofree char *checksum = NULL; + /* FIXME: Add support for collection–refs. */ context = g_option_context_new ("REF COMMIT - Reset a REF to a previous COMMIT"); if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))