lib/repo-refs: Add first version of ostree_repo_resolve_collection_ref()
authorPhilip Withnall <withnall@endlessm.com>
Tue, 26 Sep 2017 14:15:57 +0000 (15:15 +0100)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 27 Sep 2017 14:44:00 +0000 (14:44 +0000)
This is a parallel for ostree_repo_resolve_rev_ext() which works on
collection–refs. At the moment, the implementation is simple and uses
ostree_repo_list_collection_refs(). In future, it could be rewritten to
check the checksum directly rather than enumerating all
potentially-relevant checksums.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #1182
Approved by: cgwalters

apidoc/ostree-experimental-sections.txt
src/libostree/libostree-experimental.sym
src/libostree/ostree-repo-refs.c
src/libostree/ostree-repo.h

index 23412dda09162e3ee1219335a5f3684a80e823d7..c43d11e17c8cc0d4fb87e7e395dd323b37394c75 100644 (file)
@@ -85,4 +85,5 @@ ostree_repo_list_collection_refs
 ostree_repo_remote_list_collection_refs
 ostree_repo_set_collection_ref_immediate
 ostree_repo_transaction_set_collection_ref
+ostree_repo_resolve_collection_ref
 </SECTION>
index f60d4e013966d1d79853f1c0d136868f6aa20f7d..87f274dae9d7f2e576ecc71a487f581585c2a69e 100644 (file)
@@ -77,3 +77,8 @@ global:
   ostree_repo_transaction_set_collection_ref;
   ostree_validate_collection_id;
 } LIBOSTREE_2017.7_EXPERIMENTAL;
+
+LIBOSTREE_2017.12_EXPERIMENTAL {
+global:
+  ostree_repo_resolve_collection_ref;
+} LIBOSTREE_2017.8_EXPERIMENTAL;
index c6acc00b5d58124b92e2d12b7dfbb2af3a12fb08..86bdf999e0406621c3f4bc943e33b6627fa93788 100644 (file)
@@ -468,6 +468,69 @@ ostree_repo_resolve_rev_ext (OstreeRepo                    *self,
   return _ostree_repo_resolve_rev_internal (self, refspec, allow_noent, FALSE, out_rev, error);
 }
 
+#ifdef OSTREE_ENABLE_EXPERIMENTAL_API
+/**
+ * ostree_repo_resolve_collection_ref:
+ * @self: an #OstreeRepo
+ * @ref: a collection–ref to resolve
+ * @allow_noent: %TRUE to not throw an error if @ref doesn’t exist
+ * @flags: options controlling behaviour
+ * @out_rev: (out) (transfer full) (optional) (nullable): return location for
+ *    the checksum corresponding to @ref, or %NULL if @allow_noent is %TRUE and
+ *    the @ref could not be found
+ * @cancellable: (nullable): a #GCancellable, or %NULL
+ * @error: return location for a #GError, or %NULL
+ *
+ * Look up the checksum for the given collection–ref, returning it in @out_rev.
+ * This will search through the mirrors and remote refs.
+ *
+ * If @allow_noent is %TRUE and the given @ref cannot be found, %TRUE will be
+ * returned and @out_rev will be set to %NULL. If @allow_noent is %FALSE and
+ * the given @ref cannot be found, a %G_IO_ERROR_NOT_FOUND error will be
+ * returned.
+ *
+ * There are currently no @flags which affect the behaviour of this function.
+ *
+ * Returns: %TRUE on success, %FALSE on failure
+ * Since: 2017.12
+ */
+gboolean
+ostree_repo_resolve_collection_ref (OstreeRepo                    *self,
+                                    const OstreeCollectionRef     *ref,
+                                    gboolean                       allow_noent,
+                                    OstreeRepoResolveRevExtFlags   flags,
+                                    char                         **out_rev,
+                                    GCancellable                  *cancellable,
+                                    GError                       **error)
+{
+  g_return_val_if_fail (OSTREE_IS_REPO (self), FALSE);
+  g_return_val_if_fail (ref != NULL, FALSE);
+  g_return_val_if_fail (ref->collection_id != NULL && ref->ref_name != NULL, FALSE);
+  g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+  g_autoptr(GHashTable) refs = NULL;  /* (element-type OstreeCollectionRef utf8) */
+  if (!ostree_repo_list_collection_refs (self, ref->collection_id, &refs,
+                                         OSTREE_REPO_LIST_REFS_EXT_NONE,
+                                         cancellable, error))
+    return FALSE;
+
+  const char *ret_contents = g_hash_table_lookup (refs, ref);
+
+  if (ret_contents == NULL && !allow_noent)
+    {
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
+                   "Collection–ref (%s, %s) not found",
+                   ref->collection_id, ref->ref_name);
+      return FALSE;
+    }
+
+  if (out_rev != NULL)
+    *out_rev = g_strdup (ret_contents);
+  return TRUE;
+}
+#endif  /* OSTREE_ENABLE_EXPERIMENTAL_API */
+
 static gboolean
 enumerate_refs_recurse (OstreeRepo    *repo,
                         const char    *remote,
index 51b44b3f931ab27a49cd7c5ca6fdacc32381f58f..a2986e6ddc276c6ca036e8399d31471934fd08e7 100644 (file)
@@ -471,6 +471,17 @@ gboolean      ostree_repo_resolve_rev_ext (OstreeRepo                    *self,
                                            char                         **out_rev,
                                            GError                       **error);
 
+#ifdef OSTREE_ENABLE_EXPERIMENTAL_API
+_OSTREE_PUBLIC
+gboolean      ostree_repo_resolve_collection_ref (OstreeRepo                    *self,
+                                                  const OstreeCollectionRef     *ref,
+                                                  gboolean                       allow_noent,
+                                                  OstreeRepoResolveRevExtFlags   flags,
+                                                  char                         **out_rev,
+                                                  GCancellable                  *cancellable,
+                                                  GError                       **error);
+#endif  /* OSTREE_ENABLE_EXPERIMENTAL_API */
+
 _OSTREE_PUBLIC
 gboolean      ostree_repo_list_refs (OstreeRepo       *self,
                                      const char       *refspec_prefix,