ostree/builtins: Add support for collection–refs to a few utilities
authorPhilip Withnall <withnall@endlessm.com>
Fri, 9 Jun 2017 17:45:39 +0000 (18:45 +0100)
committerAtomic Bot <atomic-devel@projectatomic.io>
Mon, 26 Jun 2017 15:56:07 +0000 (15:56 +0000)
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 <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters

src/ostree/ot-builtin-fsck.c
src/ostree/ot-builtin-prune.c
src/ostree/ot-builtin-pull-local.c
src/ostree/ot-builtin-reset.c

index 936bdce4c61b10d098adba0bd01dabf389865e15..66f5536d5108e8a1c507ea07363bfa56825024e2 100644 (file)
@@ -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");
 
index 853c051fe3501ea63f73a6ab578d1a5e88eaaf72..8c595b7350d9ba1f1034491ae33a74b200e31aeb 100644 (file)
@@ -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;
index b19a4c6ae089b7f17646038eaf632984aba48763..66e189bca5a7fd6206cca751436bd95c9e69cc2f 100644 (file)
@@ -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;
index cab579aeb510680808508235924f7d842b40ae14..344d692cf515f8e5de3d340063b7c00fdf8e9045 100644 (file)
@@ -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))