From 02894b22024f3b5b0273dcd5786541f464f07ba2 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 28 Aug 2017 17:36:26 +0200 Subject: [PATCH] common: Create remote_is_already_configured() helper This will be reused later --- app/flatpak-builtins-install.c | 51 ++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/app/flatpak-builtins-install.c b/app/flatpak-builtins-install.c index e4ca2b99..0fd74b05 100644 --- a/app/flatpak-builtins-install.c +++ b/app/flatpak-builtins-install.c @@ -111,12 +111,40 @@ read_gpg_data (GCancellable *cancellable, return flatpak_read_stream (source_stream, FALSE, error); } +static gboolean +remote_is_already_configured (FlatpakDir *dir, + const char *url, + const char *collection_id) +{ + g_autofree char *old_remote = NULL; + + old_remote = flatpak_dir_find_remote_by_uri (dir, url, collection_id); + if (old_remote == NULL && flatpak_dir_is_user (dir)) + { + g_autoptr(GPtrArray) system_dirs = NULL; + int i; + + system_dirs = flatpak_dir_get_system_list (NULL, NULL); + if (system_dirs == NULL) + return FALSE; + + for (i = 0; i < system_dirs->len; i++) + { + FlatpakDir *system_dir = g_ptr_array_index (system_dirs, i); + old_remote = flatpak_dir_find_remote_by_uri (system_dir, url, collection_id); + if (old_remote != NULL) + break; + } + } + + return old_remote != NULL; +} + static gboolean handle_runtime_repo_deps (FlatpakDir *dir, const char *dep_url, GError **error) { g_autoptr(GBytes) dep_data = NULL; g_autofree char *runtime_url = NULL; - g_autofree char *old_remote = NULL; g_autofree char *new_remote = NULL; g_autofree char *basename = NULL; g_autoptr(SoupURI) uri = NULL; @@ -175,26 +203,7 @@ handle_runtime_repo_deps (FlatpakDir *dir, const char *dep_url, GError **error) runtime_collection_id = g_key_file_get_string (config, group, "collection-id", NULL); #endif /* FLATPAK_ENABLE_P2P */ - old_remote = flatpak_dir_find_remote_by_uri (dir, runtime_url, runtime_collection_id); - if (old_remote == NULL && flatpak_dir_is_user (dir)) - { - g_autoptr(GPtrArray) system_dirs = NULL; - int i; - - system_dirs = flatpak_dir_get_system_list (NULL, error); - if (system_dirs == NULL) - return FALSE; - - for (i = 0; i < system_dirs->len; i++) - { - FlatpakDir *system_dir = g_ptr_array_index (system_dirs, i); - old_remote = flatpak_dir_find_remote_by_uri (system_dir, runtime_url, runtime_collection_id); - if (old_remote != NULL) - break; - } - } - - if (old_remote != NULL) + if (remote_is_already_configured (dir, runtime_url, runtime_collection_id)) return TRUE; if (opt_yes ||