typedef struct
{
gchar *uri;
- gchar *keyring;
+ OstreeRemote *keyring_remote; /* (owned) */
} UriAndKeyring;
static void
uri_and_keyring_free (UriAndKeyring *data)
{
g_free (data->uri);
- g_free (data->keyring);
+ ostree_remote_unref (data->keyring_remote);
g_free (data);
}
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UriAndKeyring, uri_and_keyring_free)
static UriAndKeyring *
-uri_and_keyring_new (const gchar *uri,
- const gchar *keyring)
+uri_and_keyring_new (const gchar *uri,
+ OstreeRemote *keyring_remote)
{
g_autoptr(UriAndKeyring) data = NULL;
data = g_new0 (UriAndKeyring, 1);
data->uri = g_strdup (uri);
- data->keyring = g_strdup (keyring);
+ data->keyring_remote = ostree_remote_ref (keyring_remote);
return g_steal_pointer (&data);
}
{
const UriAndKeyring *_key = key;
- return g_str_hash (_key->uri) ^ g_str_hash (_key->keyring);
+ return g_str_hash (_key->uri) ^ g_str_hash (_key->keyring_remote->keyring);
}
static gboolean
{
const UriAndKeyring *_a = a, *_b = b;
- return g_str_equal (_a->uri, _b->uri) && g_str_equal (_a->keyring, _b->keyring);
+ return (g_str_equal (_a->uri, _b->uri) &&
+ g_str_equal (_a->keyring_remote->keyring, _b->keyring_remote->keyring));
}
/* This must return a valid remote name (suitable for use in a refspec). */
uri_and_keyring_to_name (UriAndKeyring *data)
{
g_autofree gchar *escaped_uri = g_uri_escape_string (data->uri, NULL, FALSE);
- g_autofree gchar *escaped_keyring = g_uri_escape_string (data->keyring, NULL, FALSE);
+ g_autofree gchar *escaped_keyring = g_uri_escape_string (data->keyring_remote->keyring, NULL, FALSE);
/* FIXME: Need a better separator than `_`, since it’s not escaped in the input. */
g_autofree gchar *out = g_strdup_printf ("%s_%s", escaped_uri, escaped_keyring);
for (i = 0; i < possible_refs->len; i++)
{
const OstreeCollectionRef *ref = g_ptr_array_index (possible_refs, i);
- g_autofree gchar *keyring = NULL;
g_autoptr(UriAndKeyring) resolved_repo = NULL;
+ g_autoptr(OstreeRemote) keyring_remote = NULL;
/* Look up the GPG keyring for this ref. */
- keyring = ostree_repo_resolve_keyring_for_collection (parent_repo, ref->collection_id,
- cancellable, &error);
+ keyring_remote = ostree_repo_resolve_keyring_for_collection (parent_repo,
+ ref->collection_id,
+ cancellable, &error);
- if (keyring == NULL)
+ if (keyring_remote == NULL)
{
g_debug ("Ignoring ref (%s, %s) on host ‘%s’ due to missing keyring: %s",
ref->collection_id, refs[i]->ref_name, service->address,
/* Add this repo to the results, keyed by the canonicalised repository URI
* to deduplicate the results. */
- g_debug ("Resolved ref (%s, %s) to repo URI ‘%s’ with keyring ‘%s’.",
- ref->collection_id, ref->ref_name, uri, keyring);
+ g_debug ("Resolved ref (%s, %s) to repo URI ‘%s’ with keyring ‘%s’ from remote ‘%s’.",
+ ref->collection_id, ref->ref_name, uri, keyring_remote->keyring,
+ keyring_remote->name);
- resolved_repo = uri_and_keyring_new (uri, keyring);
+ resolved_repo = uri_and_keyring_new (uri, keyring_remote);
supported_ref_to_checksum = g_hash_table_lookup (repo_to_refs, resolved_repo);
remote = ostree_remote_new (name);
g_clear_pointer (&remote->keyring, g_free);
- remote->keyring = g_strdup (repo->keyring);
+ remote->keyring = g_strdup (repo->keyring_remote->keyring);
/* gpg-verify-summary is false since we use the unsigned summary file support. */
g_key_file_set_string (remote->options, remote->group, "url", repo->uri);
typedef struct
{
gchar *uri;
- gchar *keyring;
+ OstreeRemote *keyring_remote; /* (owned) */
} UriAndKeyring;
static void
uri_and_keyring_free (UriAndKeyring *data)
{
g_free (data->uri);
- g_free (data->keyring);
+ ostree_remote_unref (data->keyring_remote);
g_free (data);
}
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UriAndKeyring, uri_and_keyring_free)
static UriAndKeyring *
-uri_and_keyring_new (const gchar *uri,
- const gchar *keyring)
+uri_and_keyring_new (const gchar *uri,
+ OstreeRemote *keyring_remote)
{
g_autoptr(UriAndKeyring) data = NULL;
data = g_new0 (UriAndKeyring, 1);
data->uri = g_strdup (uri);
- data->keyring = g_strdup (keyring);
+ data->keyring_remote = ostree_remote_ref (keyring_remote);
return g_steal_pointer (&data);
}
{
const UriAndKeyring *_key = key;
- return g_str_hash (_key->uri) ^ g_str_hash (_key->keyring);
+ return g_str_hash (_key->uri) ^ g_str_hash (_key->keyring_remote->keyring);
}
static gboolean
{
const UriAndKeyring *_a = a, *_b = b;
- return g_str_equal (_a->uri, _b->uri) && g_str_equal (_a->keyring, _b->keyring);
+ return (g_str_equal (_a->uri, _b->uri) &&
+ g_str_equal (_a->keyring_remote->keyring, _b->keyring_remote->keyring));
}
/* This must return a valid remote name (suitable for use in a refspec). */
uri_and_keyring_to_name (UriAndKeyring *data)
{
g_autofree gchar *escaped_uri = g_uri_escape_string (data->uri, NULL, FALSE);
- g_autofree gchar *escaped_keyring = g_uri_escape_string (data->keyring, NULL, FALSE);
+ g_autofree gchar *escaped_keyring = g_uri_escape_string (data->keyring_remote->keyring, NULL, FALSE);
/* FIXME: Need a better separator than `_`, since it’s not escaped in the input. */
g_autofree gchar *out = g_strdup_printf ("%s_%s", escaped_uri, escaped_keyring);
{
const OstreeCollectionRef *ref = refs[i];
g_autofree gchar *resolved_repo_uri = NULL;
- g_autofree gchar *keyring = NULL;
g_autoptr(UriAndKeyring) resolved_repo = NULL;
for (gsize j = 0; j < repos_refs->len; j++)
OstreeRepo *repo = repo_and_refs->repo;
GHashTable *repo_refs = repo_and_refs->refs;
g_autofree char *repo_path = g_file_get_path (ostree_repo_get_path (repo));
+ g_autoptr(OstreeRemote) keyring_remote = NULL;
const gchar *checksum = g_hash_table_lookup (repo_refs, ref);
}
/* Finally, look up the GPG keyring for this ref. */
- keyring = ostree_repo_resolve_keyring_for_collection (parent_repo, ref->collection_id,
- cancellable, &local_error);
+ keyring_remote = ostree_repo_resolve_keyring_for_collection (parent_repo,
+ ref->collection_id,
+ cancellable, &local_error);
- if (keyring == NULL)
+ if (keyring_remote == NULL)
{
g_debug ("Ignoring repository ‘%s’ when looking for ref (%s, %s) on mount ‘%s’ due to missing keyring: %s",
repo_path, ref->collection_id, ref->ref_name, mount_name, local_error->message);
* to deduplicate the results. */
g_autofree char *canonical_repo_path = realpath (repo_path, NULL);
resolved_repo_uri = g_strconcat ("file://", canonical_repo_path, NULL);
- g_debug ("Resolved ref (%s, %s) on mount ‘%s’ to repo URI ‘%s’ with keyring ‘%s’.",
- ref->collection_id, ref->ref_name, mount_name, resolved_repo_uri, keyring);
+ g_debug ("Resolved ref (%s, %s) on mount ‘%s’ to repo URI ‘%s’ with keyring ‘%s’ from remote ‘%s’.",
+ ref->collection_id, ref->ref_name, mount_name, resolved_repo_uri,
+ keyring_remote->keyring, keyring_remote->name);
- resolved_repo = uri_and_keyring_new (resolved_repo_uri, keyring);
+ resolved_repo = uri_and_keyring_new (resolved_repo_uri, keyring_remote);
supported_ref_to_checksum = g_hash_table_lookup (repo_to_refs, resolved_repo);
remote = ostree_remote_new (name);
g_clear_pointer (&remote->keyring, g_free);
- remote->keyring = g_strdup (repo->keyring);
+ remote->keyring = g_strdup (repo->keyring_remote->keyring);
/* gpg-verify-summary is false since we use the unsigned summary file support. */
g_key_file_set_string (remote->options, remote->group, "url", repo->uri);
* Find the GPG keyring for the given @collection_id, using the local
* configuration from the given #OstreeRepo. This will search the configured
* remotes for ones whose `collection-id` key matches @collection_id, and will
- * return the GPG keyring from the first matching remote.
+ * return the first matching remote.
*
* If multiple remotes match and have different keyrings, a debug message will
* be emitted, and the first result will be returned. It is expected that the
*
* If no match can be found, a %G_IO_ERROR_NOT_FOUND error will be returned.
*
- * Returns: (transfer full): filename of the GPG keyring for @collection_id
+ * Returns: (transfer full): #OstreeRemote containing the GPG keyring for
+ * @collection_id
* Since: 2017.8
*/
-gchar *
+OstreeRemote *
ostree_repo_resolve_keyring_for_collection (OstreeRepo *self,
const gchar *collection_id,
GCancellable *cancellable,
{
gsize i;
g_auto(GStrv) remotes = NULL;
- const OstreeRemote *keyring_remote = NULL;
+ OstreeRemote *keyring_remote = NULL;
g_return_val_if_fail (OSTREE_IS_REPO (self), NULL);
g_return_val_if_fail (ostree_validate_collection_id (collection_id, NULL), NULL);
}
if (keyring_remote != NULL)
- return g_strdup (keyring_remote->keyring);
+ return ostree_remote_ref (keyring_remote);
else
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
GError **error);
_OSTREE_PUBLIC
-gchar *ostree_repo_resolve_keyring_for_collection (OstreeRepo *self,
- const gchar *collection_id,
- GCancellable *cancellable,
- GError **error);
+OstreeRemote *ostree_repo_resolve_keyring_for_collection (OstreeRepo *self,
+ const gchar *collection_id,
+ GCancellable *cancellable,
+ GError **error);
_OSTREE_PUBLIC
gboolean ostree_repo_list_collection_refs (OstreeRepo *self,