[gnome-software/mwleeds/minor-offline-fixes: 1/2] flatpak: Properly detect offline case




commit fae362590265cb20364eaaf7e1b5fbb8229ccee0
Author: Phaedrus Leeds <mwleeds endlessos org>
Date:   Mon Feb 8 17:58:32 2021 -0800

    flatpak: Properly detect offline case
    
    We want to still refine what information we can if we fail to get size
    information due to being offline. There was already a check to that
    effect but the code path wasn't being hit because the
    GS_PLUGIN_ERROR_NO_NETWORK error code wasn't being set.

 plugins/flatpak/gs-flatpak.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index dd7f3ee20..70b62e8f2 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -2124,6 +2124,7 @@ gs_flatpak_fetch_remote_metadata (GsFlatpak *self,
 {
        g_autoptr(GBytes) data = NULL;
        g_autoptr(FlatpakRef) xref = NULL;
+       g_autoptr(GError) local_error = NULL;
 
        /* no origin */
        if (gs_app_get_origin (app) == NULL) {
@@ -2143,9 +2144,16 @@ gs_flatpak_fetch_remote_metadata (GsFlatpak *self,
                                                                gs_app_get_origin (app),
                                                                xref,
                                                                cancellable,
-                                                               error);
+                                                               &local_error);
        if (data == NULL) {
-               gs_flatpak_error_convert (error);
+               if (g_error_matches (local_error, FLATPAK_ERROR, FLATPAK_ERROR_REF_NOT_FOUND) &&
+                   !gs_plugin_get_network_available (self->plugin)) {
+                       local_error->code = GS_PLUGIN_ERROR_NO_NETWORK;
+                       local_error->domain = GS_PLUGIN_ERROR;
+               } else {
+                       gs_flatpak_error_convert (&local_error);
+               }
+               g_propagate_error (error, g_steal_pointer (&local_error));
                return NULL;
        }
        return g_steal_pointer (&data);
@@ -2695,8 +2703,7 @@ gs_flatpak_refine_app_unlocked (GsFlatpak *self,
                g_autoptr(GError) error_local = NULL;
                if (!gs_plugin_refine_item_size (self, app,
                                                 cancellable, &error_local)) {
-                       if (!gs_plugin_get_network_available (self->plugin) &&
-                           g_error_matches (error_local, GS_PLUGIN_ERROR,
+                       if (g_error_matches (error_local, GS_PLUGIN_ERROR,
                                             GS_PLUGIN_ERROR_NO_NETWORK)) {
                                g_debug ("failed to get size while "
                                         "refining app %s: %s",


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