[gnome-software/gnome-3-20] Make the GsPluginRefreshFlags consistent



commit 7feb2bfd0b478ccdb7644adbefe1d8c736c8fb8b
Author: Richard Hughes <richard hughsie com>
Date:   Fri Apr 15 11:49:22 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                            |   21 +++++++-
 src/gs-shell-updates.c                     |    3 +-
 src/gs-update-monitor.c                    |    3 +-
 src/plugins/gs-plugin-dummy.c              |    6 ++
 src/plugins/gs-plugin-limba.c              |    2 +-
 src/plugins/gs-plugin-packagekit-refresh.c |   77 +++++++++++++++------------
 src/plugins/gs-plugin-xdg-app.c            |   11 +++-
 8 files changed, 102 insertions(+), 43 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 32e1670..c1862e1 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -114,11 +114,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_UPDATES                 = 1 << 0,
+       GS_PLUGIN_REFRESH_FLAGS_NONE                    = 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 beec8a3..b5c4299 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -717,7 +717,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 a37c13c..2ff2e1f 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-dummy.c b/src/plugins/gs-plugin-dummy.c
index 8590f71..2f883eb 100644
--- a/src/plugins/gs-plugin-dummy.c
+++ b/src/plugins/gs-plugin-dummy.c
@@ -351,6 +351,12 @@ gs_plugin_refresh (GsPlugin *plugin,
        guint delay_ms = 100;
        g_autoptr(GsApp) app = gs_app_new (NULL);
 
+       /* each one takes more time */
+       if (flags & GS_PLUGIN_REFRESH_FLAGS_METADATA)
+               delay_ms += 3000;
+       if (flags & GS_PLUGIN_REFRESH_FLAGS_PAYLOAD)
+               delay_ms += 5000;
+
        /* do delay */
        return gs_plugin_dummy_delay (plugin, app, delay_ms, cancellable, error);
 }
diff --git a/src/plugins/gs-plugin-limba.c b/src/plugins/gs-plugin-limba.c
index 2ffe9bd..997bb8c 100644
--- a/src/plugins/gs-plugin-limba.c
+++ b/src/plugins/gs-plugin-limba.c
@@ -302,7 +302,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 2828405..71fdbff 100644
--- a/src/plugins/gs-plugin-packagekit-refresh.c
+++ b/src/plugins/gs-plugin-packagekit-refresh.c
@@ -117,16 +117,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 */
@@ -135,33 +130,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-xdg-app.c b/src/plugins/gs-plugin-xdg-app.c
index 0484d2b..340c4b2 100644
--- a/src/plugins/gs-plugin-xdg-app.c
+++ b/src/plugins/gs-plugin-xdg-app.c
@@ -601,8 +601,15 @@ gs_plugin_refresh (GsPlugin *plugin,
        guint i;
        g_autoptr(GPtrArray) xrefs = NULL;
 
-       /* not us */
-       if ((flags & GS_PLUGIN_REFRESH_FLAGS_UPDATES) == 0)
+       /* update AppStream metadata */
+       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? */


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