[gnome-software] Make the GsPluginRefreshFlags consistent



commit 2f1b8c4779434515829655652dca8da270620c65
Author: Richard Hughes <richard hughsie com>
Date:   Fri Apr 8 18:46:48 2016 +0100

    Make the GsPluginRefreshFlags consistent
    
    The UPDATES enum value was never documented and different plugins treated this
    in different ways. Rename this to METADATA and add PAYLOAD and make the
    various plugins to the right thing in all cases.
    
    Also, allow specifying the refresh flags when using gnome-software-cmd.

 src/gs-cmd.c                               |   22 +++++++-
 src/gs-plugin.h                            |   20 +++++++-
 src/gs-shell-updates.c                     |    3 +-
 src/gs-update-monitor.c                    |    3 +-
 src/plugins/gs-plugin-fwupd.c              |   13 ++++-
 src/plugins/gs-plugin-limba.c              |    2 +-
 src/plugins/gs-plugin-packagekit-refresh.c |   77 +++++++++++++++------------
 src/plugins/gs-plugin-shell-extensions.c   |    4 ++
 src/plugins/gs-plugin-xdg-app.c            |   15 +++--
 9 files changed, 110 insertions(+), 49 deletions(-)
---
diff --git a/src/gs-cmd.c b/src/gs-cmd.c
index 116315c..d1d3af8 100644
--- a/src/gs-cmd.c
+++ b/src/gs-cmd.c
@@ -175,6 +175,21 @@ gs_cmd_parse_refine_flags (const gchar *extra, GError **error)
        return refine_flags;
 }
 
+/**
+ * gs_cmd_refresh_flag_from_string:
+ **/
+static GsPluginRefreshFlags
+gs_cmd_refresh_flag_from_string (const gchar *flag)
+{
+       if (flag == NULL || g_strcmp0 (flag, "all") == 0)
+               return G_MAXINT32;
+       if (g_strcmp0 (flag, "metadata") == 0)
+               return GS_PLUGIN_REFRESH_FLAGS_METADATA;
+       if (g_strcmp0 (flag, "payload") == 0)
+               return GS_PLUGIN_REFRESH_FLAGS_PAYLOAD;
+       return GS_PLUGIN_REFRESH_FLAGS_NONE;
+}
+
 int
 main (int argc, char **argv)
 {
@@ -420,10 +435,11 @@ main (int argc, char **argv)
                                break;
                        }
                }
-       } else if (argc == 2 && g_strcmp0 (argv[1], "refresh") == 0) {
+       } else if (argc >= 2 && g_strcmp0 (argv[1], "refresh") == 0) {
+               GsPluginRefreshFlags refresh_flags;
+               refresh_flags = gs_cmd_refresh_flag_from_string (argv[2]);
                ret = gs_plugin_loader_refresh (plugin_loader, cache_age,
-                                               GS_PLUGIN_REFRESH_FLAGS_UPDATES,
-                                               NULL, &error);
+                                               refresh_flags, NULL, &error);
        } else {
                ret = FALSE;
                g_set_error_literal (&error,
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index de0d5f6..2ff6eb0 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -113,12 +113,30 @@ typedef enum {
        GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE       = 1 << 17,
        GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS          = 1 << 18,
        GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS   = 1 << 19,
+       /*< private >*/
        GS_PLUGIN_REFINE_FLAGS_LAST
 } GsPluginRefineFlags;
 
+/**
+ * GsPluginRefreshFlags:
+ * @GS_PLUGIN_REFRESH_FLAGS_NONE:      Generate new metadata if possible
+ * @GS_PLUGIN_REFRESH_FLAGS_METADATA:  Download new metadata
+ * @GS_PLUGIN_REFRESH_FLAGS_PAYLOAD:   Download any pending payload
+ *
+ * The flags used for refresh. Regeneration and downloading is only
+ * done if the cache is older than the %cache_age.
+ *
+ * The %GS_PLUGIN_REFRESH_FLAGS_METADATA can be used to make sure
+ * there's enough metadata to start the application.
+ * The %GS_PLUGIN_REFRESH_FLAGS_PAYLOAD flag should only be used when
+ * the session is idle and bandwidth is unmetered as the amount of data
+ * and IO may be large.
+ **/
 typedef enum {
        GS_PLUGIN_REFRESH_FLAGS_NONE                    = 0,
-       GS_PLUGIN_REFRESH_FLAGS_UPDATES                 = 1 << 0,
+       GS_PLUGIN_REFRESH_FLAGS_METADATA                = 1 << 0,
+       GS_PLUGIN_REFRESH_FLAGS_PAYLOAD                 = 1 << 1,
+       /*< private >*/
        GS_PLUGIN_REFRESH_FLAGS_LAST
 } GsPluginRefreshFlags;
 
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index 1ecd274..08a49eb 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -736,7 +736,8 @@ gs_shell_updates_get_new_updates (GsShellUpdates *self)
 
        gs_plugin_loader_refresh_async (self->plugin_loader,
                                        10 * 60,
-                                       GS_PLUGIN_REFRESH_FLAGS_UPDATES,
+                                       GS_PLUGIN_REFRESH_FLAGS_METADATA |
+                                       GS_PLUGIN_REFRESH_FLAGS_PAYLOAD,
                                        self->cancellable_refresh,
                                        (GAsyncReadyCallback) gs_shell_updates_refresh_cb,
                                        self);
diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c
index 0397c7a..032a96f 100644
--- a/src/gs-update-monitor.c
+++ b/src/gs-update-monitor.c
@@ -333,7 +333,8 @@ check_updates (GsUpdateMonitor *monitor)
        g_debug ("Refreshing cache");
        gs_plugin_loader_refresh_async (monitor->plugin_loader,
                                        60 * 60 * 24,
-                                       GS_PLUGIN_REFRESH_FLAGS_UPDATES,
+                                       GS_PLUGIN_REFRESH_FLAGS_METADATA |
+                                       GS_PLUGIN_REFRESH_FLAGS_PAYLOAD,
                                        monitor->cancellable,
                                        refresh_cache_finished_cb,
                                        monitor);
diff --git a/src/plugins/gs-plugin-fwupd.c b/src/plugins/gs-plugin-fwupd.c
index 246b5b6..7fedddf 100644
--- a/src/plugins/gs-plugin-fwupd.c
+++ b/src/plugins/gs-plugin-fwupd.c
@@ -590,8 +590,17 @@ gs_plugin_refresh (GsPlugin *plugin,
                return FALSE;
 
        /* get the metadata and signature file */
-       if (!gs_plugin_fwupd_check_lvfs_metadata (plugin, cache_age, cancellable, error))
-               return FALSE;
+       if (flags & GS_PLUGIN_REFRESH_FLAGS_METADATA) {
+               if (!gs_plugin_fwupd_check_lvfs_metadata (plugin,
+                                                         cache_age,
+                                                         cancellable,
+                                                         error))
+                       return FALSE;
+       }
+
+       /* no longer interesting */
+       if ((flags & GS_PLUGIN_REFRESH_FLAGS_PAYLOAD) == 0)
+               return TRUE;
 
        /* download the files to the cachedir */
        for (i = 0; i < plugin->priv->to_download->len; i++) {
diff --git a/src/plugins/gs-plugin-limba.c b/src/plugins/gs-plugin-limba.c
index e1bfabc..5162d0f 100644
--- a/src/plugins/gs-plugin-limba.c
+++ b/src/plugins/gs-plugin-limba.c
@@ -280,7 +280,7 @@ gs_plugin_refresh (GsPlugin *plugin,
        GError *error_local = NULL;
 
        /* not us */
-       if ((flags & GS_PLUGIN_REFRESH_FLAGS_UPDATES) == 0)
+       if ((flags & GS_PLUGIN_REFRESH_FLAGS_METADATA) == 0)
                return TRUE;
 
        mgr = li_manager_new ();
diff --git a/src/plugins/gs-plugin-packagekit-refresh.c b/src/plugins/gs-plugin-packagekit-refresh.c
index a514967..0348f3c 100644
--- a/src/plugins/gs-plugin-packagekit-refresh.c
+++ b/src/plugins/gs-plugin-packagekit-refresh.c
@@ -129,16 +129,11 @@ gs_plugin_refresh (GsPlugin *plugin,
                   GCancellable *cancellable,
                   GError **error)
 {
-       PkBitfield filter;
-       PkBitfield transaction_flags;
        ProgressData data;
-       g_auto(GStrv) package_ids = NULL;
-       g_autoptr(PkPackageSack) sack = NULL;
-       g_autoptr(PkResults) results2 = NULL;
        g_autoptr(PkResults) results = NULL;
 
-       /* not us */
-       if ((flags & GS_PLUGIN_REFRESH_FLAGS_UPDATES) == 0)
+       /* nothing to re-generate */
+       if (flags == 0)
                return TRUE;
 
        /* cache age of 0 is user-initiated */
@@ -147,33 +142,47 @@ gs_plugin_refresh (GsPlugin *plugin,
        data.plugin = plugin;
        data.ptask = NULL;
 
-       /* update UI as this might take some time */
-       gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
-
-       /* do sync call */
-       filter = pk_bitfield_value (PK_FILTER_ENUM_NONE);
-       pk_client_set_cache_age (PK_CLIENT (plugin->priv->task), cache_age);
-       results = pk_client_get_updates (PK_CLIENT (plugin->priv->task),
-                                        filter,
-                                        cancellable,
-                                        gs_plugin_packagekit_progress_cb, &data,
-                                        error);
-       if (results == NULL)
-               return FALSE;
+       /* refresh the metadata */
+       if (flags & GS_PLUGIN_REFRESH_FLAGS_METADATA ||
+           flags & GS_PLUGIN_REFRESH_FLAGS_PAYLOAD) {
+               PkBitfield filter;
+
+               filter = pk_bitfield_value (PK_FILTER_ENUM_NONE);
+               pk_client_set_cache_age (PK_CLIENT (plugin->priv->task), cache_age);
+               gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
+               results = pk_client_get_updates (PK_CLIENT (plugin->priv->task),
+                                                filter,
+                                                cancellable,
+                                                gs_plugin_packagekit_progress_cb, &data,
+                                                error);
+               if (results == NULL)
+                       return FALSE;
+       }
 
-       /* download all the updates */
-       sack = pk_results_get_package_sack (results);
-       if (pk_package_sack_get_size (sack) == 0)
-               return TRUE;
-       package_ids = pk_package_sack_get_ids (sack);
-       transaction_flags = pk_bitfield_value (PK_TRANSACTION_FLAG_ENUM_ONLY_DOWNLOAD);
-       results2 = pk_client_update_packages (PK_CLIENT (plugin->priv->task),
-                                             transaction_flags,
-                                             package_ids,
-                                             cancellable,
-                                             gs_plugin_packagekit_progress_cb, &data,
-                                             error);
-       return results2 != NULL;
+       /* download all the packages themselves */
+       if (flags & GS_PLUGIN_REFRESH_FLAGS_PAYLOAD) {
+               PkBitfield transaction_flags;
+               g_auto(GStrv) package_ids = NULL;
+               g_autoptr(PkPackageSack) sack = NULL;
+               g_autoptr(PkResults) results2 = NULL;
+
+               sack = pk_results_get_package_sack (results);
+               if (pk_package_sack_get_size (sack) == 0)
+                       return TRUE;
+               package_ids = pk_package_sack_get_ids (sack);
+               transaction_flags = pk_bitfield_value (PK_TRANSACTION_FLAG_ENUM_ONLY_DOWNLOAD);
+               gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
+               results2 = pk_client_update_packages (PK_CLIENT (plugin->priv->task),
+                                                     transaction_flags,
+                                                     package_ids,
+                                                     cancellable,
+                                                     gs_plugin_packagekit_progress_cb, &data,
+                                                     error);
+               if (results2 == NULL)
+                       return FALSE;
+       }
+
+       return TRUE;
 }
 
 /**
diff --git a/src/plugins/gs-plugin-shell-extensions.c b/src/plugins/gs-plugin-shell-extensions.c
index 1029bc4..224411b 100644
--- a/src/plugins/gs-plugin-shell-extensions.c
+++ b/src/plugins/gs-plugin-shell-extensions.c
@@ -664,6 +664,10 @@ gs_plugin_refresh (GsPlugin *plugin,
        g_autoptr(AsStore) store = NULL;
        g_autoptr(GFile) file = NULL;
 
+       /* no longer interesting */
+       if ((flags & GS_PLUGIN_REFRESH_FLAGS_METADATA) == 0)
+               return TRUE;
+
        /* connect to gnome-shell */
        if (!gs_plugin_setup (plugin, cancellable, error))
                return FALSE;
diff --git a/src/plugins/gs-plugin-xdg-app.c b/src/plugins/gs-plugin-xdg-app.c
index b805125..6b8d147 100644
--- a/src/plugins/gs-plugin-xdg-app.c
+++ b/src/plugins/gs-plugin-xdg-app.c
@@ -618,17 +618,20 @@ gs_plugin_refresh (GsPlugin *plugin,
        guint i;
        g_autoptr(GPtrArray) xrefs = NULL;
 
-       /* not us */
-       if ((flags & GS_PLUGIN_REFRESH_FLAGS_UPDATES) == 0)
-               return TRUE;
-
        /* ensure we can set up the repo */
        if (!gs_plugin_ensure_installation (plugin, cancellable, error))
                return FALSE;
 
        /* update AppStream metadata */
-       if (!gs_plugin_refresh_appstream (plugin, cache_age, cancellable, error))
-               return FALSE;
+       if (flags & GS_PLUGIN_REFRESH_FLAGS_METADATA) {
+               if (!gs_plugin_refresh_appstream (plugin, cache_age,
+                                                 cancellable, error))
+                       return FALSE;
+       }
+
+       /* no longer interesting */
+       if ((flags & GS_PLUGIN_REFRESH_FLAGS_PAYLOAD) == 0)
+               return TRUE;
 
        /* use helper: FIXME: new()&ref? */
        helper.plugin = plugin;


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