summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2018-11-15 17:03:34 +0100
committerAlexander Larsson <alexl@redhat.com>2018-11-16 11:34:07 +0100
commit4e257beab0cef2ff7038729f453dedc4917d02d1 (patch)
treec4a0e3f07ba0ee2b8719f41b17bf39c128332ad2
parent269796028cfa9127dc446cd6e3463832fb525851 (diff)
downloadflatpak-4e257beab0cef2ff7038729f453dedc4917d02d1.tar.gz
dir: Match pre-existing remotes better wrt collection-id
If you have a pre-existing remote configured its exact definition might differ from the one specified in a flatpakrepo file and yet be the same. For example, i have: $ flatpak --user remotes -d Name Title URL Collection ID Priority Options flathub Flathub https://dl.flathub.org/repo/ org.flathub.Stable 1 Yet when i install a flatpakref: $ flatpak --user install http://flathub.org/repo/appstream/org.gnome.gedit.flatpakref The application org.gnome.gedit depends on runtimes from: https://dl.flathub.org/repo/ Configure this as new remote 'flathub-1' [y/n]: Because the flathub flatpakrepo does not yet have the collection id specified. So, we need to be more lenient when matching the pre-configured remotes. Closes: #2324 Approved by: alexlarsson (cherry picked from commit 1ce0246b0d8012193f8a4f63579162916c3e2e69)
-rw-r--r--common/flatpak-dir.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c
index b01c1251..f1a36ebc 100644
--- a/common/flatpak-dir.c
+++ b/common/flatpak-dir.c
@@ -10877,6 +10877,21 @@ flatpak_dir_create_remote_for_ref_file (FlatpakDir *self,
return TRUE;
}
+/* This tries to find a pre-configured remote for the specified uri
+ * and (optionally) collection id. This is a bit more complex than it
+ * sounds, because a local remote could be configured in different
+ * ways for a remote repo (i.e. it could be not using collection ids,
+ * even though the remote specifies it, or the flatpakrepo might lack
+ * the collection id details). So, we use these rules:
+ *
+ * If the url is the same, it is a match even if one part lacks
+ * collection ids. However, if both collection ids are specified and
+ * differ there is no match.
+ *
+ * If the collection id is the same (and specified), its going to be
+ * the same remote, even if the url is different (because it could be
+ * some other mirror of the same repo).
+ */
char *
flatpak_dir_find_remote_by_uri (FlatpakDir *self,
const char *uri,
@@ -10906,8 +10921,18 @@ flatpak_dir_find_remote_by_uri (FlatpakDir *self,
if (!repo_get_remote_collection_id (self->repo, remote, &remote_collection_id, NULL))
continue;
+ /* Exact collection ids always match, independent of the uris used */
+ if (collection_id != NULL &&
+ remote_collection_id != NULL &&
+ strcmp (collection_id, remote_collection_id) == 0)
+ return g_strdup (remote);
+
+ /* Same repo if uris matches, unless both have collection-id
+ specified but different */
if (strcmp (uri, remote_uri) == 0 &&
- g_strcmp0 (collection_id, remote_collection_id) == 0)
+ !(collection_id != NULL &&
+ remote_collection_id != NULL &&
+ strcmp (collection_id, remote_collection_id) != 0))
return g_strdup (remote);
}
}