[gnome-software: 11/38] fwupd: Remove unhelpful helper function




commit ccf37e1f68bd4854a6ccb734059daba2e8423fde
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Feb 2 17:14:07 2022 +0000

    fwupd: Remove unhelpful helper function
    
    If refreshing metadata in the fwupd plugin is to be async,
    `gs_plugin_fwupd_refresh_remote()` would have to be made async. That’s
    quite a lot of boilerplate for very little function code — so it seems
    to make more sense to split the function into a helper to check the
    cache age, and the actual libfwupd call. The libfwupd call already has
    an async version.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1472

 plugins/fwupd/gs-plugin-fwupd.c | 35 ++++++++++++++++-------------------
 1 file changed, 16 insertions(+), 19 deletions(-)
---
diff --git a/plugins/fwupd/gs-plugin-fwupd.c b/plugins/fwupd/gs-plugin-fwupd.c
index db2d3b62d..f676d2887 100644
--- a/plugins/fwupd/gs-plugin-fwupd.c
+++ b/plugins/fwupd/gs-plugin-fwupd.c
@@ -697,28 +697,18 @@ gs_plugin_add_updates (GsPlugin *plugin,
 }
 
 static gboolean
-gs_plugin_fwupd_refresh_remote (GsPluginFwupd  *self,
-                                FwupdRemote    *remote,
-                                guint           cache_age,
-                                GCancellable   *cancellable,
-                                GError        **error)
+remote_cache_is_expired (FwupdRemote *remote,
+                         guint64      cache_age_secs)
 {
        /* check cache age */
-       if (cache_age > 0) {
+       if (cache_age_secs > 0) {
                guint64 age = fwupd_remote_get_age (remote);
-               guint tmp = age < G_MAXUINT ? (guint) age : G_MAXUINT;
-               if (tmp < cache_age) {
-                       g_debug ("fwupd remote is only %u seconds old, so ignoring refresh", tmp);
-                       return TRUE;
+               if (age < cache_age_secs) {
+                       g_debug ("fwupd remote is only %" G_GUINT64_FORMAT " seconds old, so ignoring 
refresh", age);
+                       return FALSE;
                }
        }
 
-       /* download new content */
-       if (!fwupd_client_refresh_remote (self->client, remote, cancellable, error)) {
-               gs_plugin_fwupd_error_convert (error);
-               return FALSE;
-       }
-
        return TRUE;
 }
 
@@ -750,9 +740,13 @@ gs_plugin_refresh (GsPlugin *plugin,
                        continue;
                if (fwupd_remote_get_kind (remote) != FWUPD_REMOTE_KIND_DOWNLOAD)
                        continue;
-               if (!gs_plugin_fwupd_refresh_remote (self, remote, cache_age,
-                                                    cancellable, error))
+               if (!remote_cache_is_expired (remote, cache_age))
+                       continue;
+
+               if (!fwupd_client_refresh_remote (self->client, remote, cancellable, error)) {
+                       gs_plugin_fwupd_error_convert (error);
                        return FALSE;
+               }
        }
        return TRUE;
 }
@@ -1138,8 +1132,11 @@ gs_plugin_fwupd_refresh_single_remote (GsPluginFwupd *self,
                if (g_strcmp0 (remote_id, fwupd_remote_get_id (remote)) == 0) {
                        if (fwupd_remote_get_enabled (remote) &&
                            fwupd_remote_get_kind (remote) != FWUPD_REMOTE_KIND_LOCAL &&
-                           !gs_plugin_fwupd_refresh_remote (self, remote, cache_age, cancellable, error))
+                           !remote_cache_is_expired (remote, cache_age) &&
+                           !fwupd_client_refresh_remote (self->client, remote, cancellable, error)) {
+                               gs_plugin_fwupd_error_convert (error);
                                return FALSE;
+                       }
                        break;
                }
        }


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