diff --git a/apidoc/ostree-experimental-sections.txt b/apidoc/ostree-experimental-sections.txt index 23412dda..c43d11e1 100644 --- a/apidoc/ostree-experimental-sections.txt +++ b/apidoc/ostree-experimental-sections.txt @@ -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 diff --git a/src/libostree/libostree-experimental.sym b/src/libostree/libostree-experimental.sym index f60d4e01..87f274da 100644 --- a/src/libostree/libostree-experimental.sym +++ b/src/libostree/libostree-experimental.sym @@ -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; diff --git a/src/libostree/ostree-repo-refs.c b/src/libostree/ostree-repo-refs.c index c6acc00b..86bdf999 100644 --- a/src/libostree/ostree-repo-refs.c +++ b/src/libostree/ostree-repo-refs.c @@ -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, diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h index 51b44b3f..a2986e6d 100644 --- a/src/libostree/ostree-repo.h +++ b/src/libostree/ostree-repo.h @@ -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,