[gnome-software] flatpak: Do not show an error for a flatpakref when broken remotes exist



commit 4caafedb51c04eef17140c8cdadd2d5d5a204473
Author: Richard Hughes <richard hughsie com>
Date:   Tue Jul 18 13:03:57 2017 +0100

    flatpak: Do not show an error for a flatpakref when broken remotes exist
    
    The configured remote URI might be invalid, or it might only be reachable from
    behind a VPN.

 plugins/flatpak/gs-flatpak.c        |   14 +++++-
 plugins/flatpak/gs-plugin-flatpak.c |    4 +-
 plugins/flatpak/gs-self-test.c      |   83 +++++++++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+), 4 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 7525c40..535dcac 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -948,13 +948,21 @@ gs_flatpak_find_app (GsFlatpak *self,
        }
        for (guint i = 0; i < xremotes->len; i++) {
                FlatpakRemote *xremote = g_ptr_array_index (xremotes, i);
+               g_autoptr(GError) error_local = NULL;
                g_autoptr(GPtrArray) refs_remote = NULL;
+
+               /* disabled */
+               if (flatpak_remote_get_disabled (xremote))
+                       continue;
                refs_remote = flatpak_installation_list_remote_refs_sync (self->installation,
                                                                          flatpak_remote_get_name (xremote),
-                                                                         cancellable, error);
+                                                                         cancellable,
+                                                                         &error_local);
                if (refs_remote == NULL) {
-                       gs_flatpak_error_convert (error);
-                       return FALSE;
+                       g_debug ("failed to list refs in '%s': %s",
+                                flatpak_remote_get_name (xremote),
+                                error_local->message);
+                       continue;
                }
                for (guint j = 0; j < refs_remote->len; j++) {
                        FlatpakRef *xref = g_ptr_array_index (refs_remote, j);
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index 9699bc0..3178b88 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -572,8 +572,10 @@ gs_plugin_flatpak_file_to_app_ref (GsPlugin *plugin,
                                          gs_flatpak_app_get_ref_name (app_tmp),
                                          gs_flatpak_app_get_ref_arch (app_tmp),
                                          gs_flatpak_app_get_ref_branch (app_tmp),
-                                         list_tmp, cancellable, error))
+                                         list_tmp, cancellable, error)) {
+                       g_prefix_error (error, "failed to find in existing remotes: ");
                        return FALSE;
+               }
        }
        for (guint i = 0; i < gs_app_list_length (list_tmp); i++) {
                GsApp *app_old = gs_app_list_index (list_tmp, i);
diff --git a/plugins/flatpak/gs-self-test.c b/plugins/flatpak/gs-self-test.c
index cea6751..4d6131e 100644
--- a/plugins/flatpak/gs-self-test.c
+++ b/plugins/flatpak/gs-self-test.c
@@ -890,6 +890,86 @@ gs_plugins_flatpak_runtime_repo_redundant_func (GsPluginLoader *plugin_loader)
 }
 
 static void
+gs_plugins_flatpak_broken_remote_func (GsPluginLoader *plugin_loader)
+{
+       gboolean ret;
+       const gchar *fn = "/tmp/test.flatpakref";
+       g_autofree gchar *testdir2 = NULL;
+       g_autofree gchar *testdir2_repourl = NULL;
+       g_autofree gchar *testdir = NULL;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GFile) file = NULL;
+       g_autoptr(GsApp) app = NULL;
+       g_autoptr(GsApp) app_source = NULL;
+       g_autoptr(GsPluginJob) plugin_job = NULL;
+
+       /* drop all caches */
+       gs_plugin_loader_setup_again (plugin_loader);
+
+       /* no flatpak, abort */
+       if (!gs_plugin_loader_get_enabled (plugin_loader, "flatpak"))
+               return;
+
+       /* add a remote with only the runtime in */
+       app_source = gs_flatpak_app_new ("test");
+       testdir = gs_test_get_filename (TESTDATADIR, "only-runtime");
+       if (testdir == NULL)
+               return;
+       gs_app_set_kind (app_source, AS_APP_KIND_SOURCE);
+       gs_app_set_management_plugin (app_source, "flatpak");
+       gs_app_set_state (app_source, AS_APP_STATE_AVAILABLE);
+       gs_flatpak_app_set_repo_url (app_source, "file:///wont/work");
+       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL,
+                                        "app", app_source,
+                                        NULL);
+       ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
+       g_assert_no_error (error);
+       g_assert (ret);
+       g_assert_cmpint (gs_app_get_state (app_source), ==, AS_APP_STATE_INSTALLED);
+
+       /* write a flatpakref file */
+       testdir2 = gs_test_get_filename (TESTDATADIR, "app-with-runtime");
+       if (testdir2 == NULL)
+               return;
+       testdir2_repourl = g_strdup_printf ("file://%s/repo", testdir2);
+       ret = gs_flatpak_test_write_ref_file (fn, testdir2_repourl, NULL, &error);
+       g_assert_no_error (error);
+       g_assert (ret);
+
+       /* convert it to a GsApp */
+       file = g_file_new_for_path (fn);
+       g_object_unref (plugin_job);
+       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_FILE_TO_APP,
+                                        "file", file,
+                                        "refine-flags", GS_PLUGIN_REFINE_FLAGS_REQUIRE_VERSION |
+                                                        GS_PLUGIN_REFINE_FLAGS_REQUIRE_RUNTIME,
+                                        NULL);
+       app = gs_plugin_loader_job_process_app (plugin_loader, plugin_job, NULL, &error);
+       g_assert_no_error (error);
+       g_assert (app != NULL);
+       g_assert_cmpint (gs_app_get_kind (app), ==, AS_APP_KIND_DESKTOP);
+       g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_AVAILABLE_LOCAL);
+       g_assert_cmpstr (gs_app_get_id (app), ==, "org.test.Chiron.desktop");
+       g_assert (as_utils_unique_id_equal (gs_app_get_unique_id (app),
+                       "user/flatpak/org.test.Chiron-origin/desktop/org.test.Chiron.desktop/master"));
+       g_assert_cmpstr (gs_app_get_url (app, AS_URL_KIND_HOMEPAGE), ==, "http://127.0.0.1/";);
+       g_assert_cmpstr (gs_app_get_name (app), ==, "Chiron");
+       g_assert_cmpstr (gs_app_get_summary (app), ==, "Single line synopsis");
+       g_assert_cmpstr (gs_app_get_description (app), ==, "Long description.");
+       g_assert_cmpstr (gs_app_get_version (app), ==, "1.2.3");
+       g_assert (gs_app_get_local_file (app) != NULL);
+
+       /* remove source */
+       g_object_unref (plugin_job);
+       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE,
+                                        "app", app_source,
+                                        NULL);
+       ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
+       g_assert_no_error (error);
+       g_assert (ret);
+}
+
+static void
 gs_plugins_flatpak_ref_func (GsPluginLoader *plugin_loader)
 {
        GsApp *app_tmp;
@@ -1398,6 +1478,9 @@ main (int argc, char **argv)
        g_test_add_data_func ("/gnome-software/plugins/flatpak/ref",
                              plugin_loader,
                              (GTestDataFunc) gs_plugins_flatpak_ref_func);
+       g_test_add_data_func ("/gnome-software/plugins/flatpak/broken-remote",
+                             plugin_loader,
+                             (GTestDataFunc) gs_plugins_flatpak_broken_remote_func);
        g_test_add_data_func ("/gnome-software/plugins/flatpak/runtime-repo",
                              plugin_loader,
                              (GTestDataFunc) gs_plugins_flatpak_runtime_repo_func);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]