lib/remote: Store name of remote providing keyring for dynamic remotes
authorPhilip Withnall <withnall@endlessm.com>
Thu, 21 Sep 2017 15:04:11 +0000 (16:04 +0100)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 27 Sep 2017 16:38:07 +0000 (16:38 +0000)
When pulling from a dynamic (peer to peer) remote, the remote’s name is
set to a unique, generated string which doesn’t exist in repo/config. If
doing a non-mirror pull, however, we don’t want to use this name in the
refspecs for newly created or updated refs — we want to use the name of
the remote which provided the keyring for the pull (this will be a
remote from repo/config whose collection ID matches that being used for
the peer to peer pull).

Store both names in OstreeRemote. The name to use for refspecs is stored
as refspec_name, and is typically NULL unless it differs from name.

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

src/libostree/ostree-remote-private.h
src/libostree/ostree-remote.c
src/libostree/ostree-repo-finder-avahi.c
src/libostree/ostree-repo-finder-mount.c

index b7e9eb3bb895d2045618ff8032f8d1827bfc9642..ff7f885b1570ad1d3f6e4506fb5b99e65e76b8df 100644 (file)
 
 G_BEGIN_DECLS
 
+/* @refspec_name is set if this is a dynamic remote. It’s the name of the static
+ * remote which this one inherits from, and is what should be used in refspecs
+ * for pulls from this remote. If it’s %NULL, @name should be used instead. */
 struct OstreeRemote {
   volatile int ref_count;
   char *name;  /* (not nullable) */
+  char *refspec_name;  /* (nullable) */
   char *group;   /* group name in options (not nullable) */
-  char *keyring; /* keyring name (NAME.trustedkeys.gpg) (not nullable) */
+  char *keyring; /* keyring name ($refspec_name.trustedkeys.gpg) (not nullable) */
   GFile *file;   /* NULL if remote defined in repo/config */
   GKeyFile *options;
 };
 
 G_GNUC_INTERNAL
 OstreeRemote *ostree_remote_new (const gchar *name);
+G_GNUC_INTERNAL
+OstreeRemote *ostree_remote_new_dynamic (const gchar *name,
+                                         const gchar *refspec_name);
 
 G_GNUC_INTERNAL
 OstreeRemote *ostree_remote_new_from_keyfile (GKeyFile    *keyfile,
index cac7838c669f646f899ca111082efcaa50ef5cb1..605a7eb9b0911f01f60827861ea44b8dae00abc6 100644 (file)
 
 OstreeRemote *
 ostree_remote_new (const gchar *name)
+{
+  return ostree_remote_new_dynamic (name, NULL);
+}
+
+OstreeRemote *
+ostree_remote_new_dynamic (const gchar *name,
+                           const gchar *refspec_name)
 {
   OstreeRemote *remote;
 
   g_return_val_if_fail (name != NULL && *name != '\0', NULL);
+  g_return_val_if_fail (refspec_name == NULL || *refspec_name != '\0', NULL);
 
   remote = g_slice_new0 (OstreeRemote);
   remote->ref_count = 1;
   remote->name = g_strdup (name);
-  remote->group = g_strdup_printf ("remote \"%s\"", name);
-  remote->keyring = g_strdup_printf ("%s.trustedkeys.gpg", name);
+  remote->refspec_name = g_strdup (refspec_name);
+  remote->group = g_strdup_printf ("remote \"%s\"", (refspec_name != NULL) ? refspec_name : name);
+  remote->keyring = g_strdup_printf ("%s.trustedkeys.gpg", (refspec_name != NULL) ? refspec_name : name);
   remote->options = g_key_file_new ();
 
   return remote;
index 409fcae830ec73393078f4df7e15c2f6fa779332..a39d95339b714082a2e81dad799b5c1fa3665903 100644 (file)
@@ -821,7 +821,7 @@ ostree_avahi_service_build_repo_finder_result (OstreeAvahiService
       /* Build an #OstreeRemote. Use the escaped URI, since remote->name
        * is used in file paths, so needs to not contain special characters. */
       g_autofree gchar *name = uri_and_keyring_to_name (repo);
-      remote = ostree_remote_new (name);
+      remote = ostree_remote_new_dynamic (name, repo->keyring_remote->name);
 
       g_clear_pointer (&remote->keyring, g_free);
       remote->keyring = g_strdup (repo->keyring_remote->keyring);
index 7dcbab892b01d4bc0ecac3fcd45925d7cd10d739..c385e70c8ab49006028d48cb901380385f8ab840 100644 (file)
@@ -513,7 +513,7 @@ ostree_repo_finder_mount_resolve_async (OstreeRepoFinder                  *finde
           /* Build an #OstreeRemote. Use the escaped URI, since remote->name
            * is used in file paths, so needs to not contain special characters. */
           g_autofree gchar *name = uri_and_keyring_to_name (repo);
-          remote = ostree_remote_new (name);
+          remote = ostree_remote_new_dynamic (name, repo->keyring_remote->name);
 
           g_clear_pointer (&remote->keyring, g_free);
           remote->keyring = g_strdup (repo->keyring_remote->keyring);