[gnome-software] Use the plugin name as part of the cache filename



commit 8864182179107ea7b4083ed09a849c121e7f78fc
Author: Richard Hughes <richard hughsie com>
Date:   Thu Sep 14 18:10:42 2017 +0100

    Use the plugin name as part of the cache filename

 lib/gs-utils.c                                     |    7 ++++++-
 .../gs-plugin-fedora-pkgdb-collections.c           |    2 +-
 plugins/fwupd/gs-plugin-fwupd.c                    |   10 +++++-----
 plugins/odrs/gs-plugin-odrs.c                      |    8 ++++----
 .../shell-extensions/gs-plugin-shell-extensions.c  |    2 +-
 5 files changed, 17 insertions(+), 12 deletions(-)
---
diff --git a/lib/gs-utils.c b/lib/gs-utils.c
index ccdb1f6..1ba2f58 100644
--- a/lib/gs-utils.c
+++ b/lib/gs-utils.c
@@ -127,7 +127,7 @@ gs_utils_filename_array_return_newest (GPtrArray *array)
 
 /**
  * gs_utils_get_cache_filename:
- * @kind: A cache kind, e.g. "firmware" or "screenshots/123x456"
+ * @kind: A cache kind, e.g. "fwupd" or "screenshots/123x456"
  * @resource: A resource, e.g. "system.bin" or "http://foo.bar/baz.bin";
  * @flags: Some #GsUtilsCacheFlags, e.g. %GS_UTILS_CACHE_FLAG_WRITEABLE
  * @error: A #GError, or %NULL
@@ -142,6 +142,11 @@ gs_utils_filename_array_return_newest (GPtrArray *array)
  * If there is more than one match, the file that has been modified last is
  * returned.
  *
+ * If a plugin requests a file to be saved in the cache it is the plugins
+ * responsibility to remove the file when it is no longer valid or is too old
+ * -- gnome-software will not ever clean the cache for the plugin.
+ * For this reason it is a good idea to use the plugin name as @kind.
+ *
  * Returns: The full path and filename, which may or may not exist, or %NULL
  **/
 gchar *
diff --git a/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c 
b/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
index 46aeefa..ea4738f 100644
--- a/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
+++ b/plugins/fedora-pkgdb-collections/gs-plugin-fedora-pkgdb-collections.c
@@ -131,7 +131,7 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
        g_autoptr(GsOsRelease) os_release = NULL;
 
        /* get the file to cache */
-       priv->cachefn = gs_utils_get_cache_filename ("upgrades",
+       priv->cachefn = gs_utils_get_cache_filename ("fedora-pkgdb-collections",
                                                     "fedora.json",
                                                     GS_UTILS_CACHE_FLAG_WRITEABLE,
                                                     error);
diff --git a/plugins/fwupd/gs-plugin-fwupd.c b/plugins/fwupd/gs-plugin-fwupd.c
index 112efbd..ced7d40 100644
--- a/plugins/fwupd/gs-plugin-fwupd.c
+++ b/plugins/fwupd/gs-plugin-fwupd.c
@@ -248,7 +248,7 @@ gs_plugin_fwupd_setup_remote (GsPlugin *plugin, FwupdRemote *remote, GError **er
                return TRUE;
 
        /* find the name of the signature file in the cache */
-       filename_asc = gs_utils_get_cache_filename ("firmware",
+       filename_asc = gs_utils_get_cache_filename ("fwupd",
                                                    fwupd_remote_get_filename_asc (remote),
                                                    GS_UTILS_CACHE_FLAG_WRITEABLE,
                                                    error);
@@ -456,7 +456,7 @@ gs_plugin_add_update_app (GsPlugin *plugin,
 
        /* does the firmware already exist in the cache? */
        basename = g_path_get_basename (update_uri);
-       filename_cache = gs_utils_get_cache_filename ("firmware",
+       filename_cache = gs_utils_get_cache_filename ("fwupd",
                                                      basename,
                                                      GS_UTILS_CACHE_FLAG_NONE,
                                                      error);
@@ -655,7 +655,7 @@ gs_plugin_fwupd_refresh_remote (GsPlugin *plugin,
        }
 
        /* check cache age */
-       filename_asc = gs_utils_get_cache_filename ("firmware",
+       filename_asc = gs_utils_get_cache_filename ("fwupd",
                                                    fwupd_remote_get_filename_asc (remote),
                                                    GS_UTILS_CACHE_FLAG_WRITEABLE,
                                                    error);
@@ -710,7 +710,7 @@ gs_plugin_fwupd_refresh_remote (GsPlugin *plugin,
                             g_steal_pointer (&checksum));
 
        /* download the payload and save to file */
-       filename = gs_utils_get_cache_filename ("firmware",
+       filename = gs_utils_get_cache_filename ("fwupd",
                                                fwupd_remote_get_filename (remote),
                                                GS_UTILS_CACHE_FLAG_WRITEABLE,
                                                error);
@@ -799,7 +799,7 @@ gs_plugin_refresh (GsPlugin *plugin,
 
                tmp = g_ptr_array_index (priv->to_download, i);
                basename = g_path_get_basename (tmp);
-               filename_cache = gs_utils_get_cache_filename ("firmware",
+               filename_cache = gs_utils_get_cache_filename ("fwupd",
                                                              basename,
                                                              GS_UTILS_CACHE_FLAG_WRITEABLE,
                                                              error);
diff --git a/plugins/odrs/gs-plugin-odrs.c b/plugins/odrs/gs-plugin-odrs.c
index 328cd42..584b4b0 100644
--- a/plugins/odrs/gs-plugin-odrs.c
+++ b/plugins/odrs/gs-plugin-odrs.c
@@ -180,8 +180,8 @@ gs_plugin_odrs_refresh_ratings (GsPlugin *plugin,
        g_autoptr(GsApp) app_dl = gs_app_new (gs_plugin_get_name (plugin));
 
        /* check cache age */
-       fn = gs_utils_get_cache_filename ("ratings",
-                                         "odrs.json",
+       fn = gs_utils_get_cache_filename ("odrs",
+                                         "ratings.json",
                                          GS_UTILS_CACHE_FLAG_WRITEABLE,
                                          error);
        if (fn == NULL)
@@ -600,7 +600,7 @@ gs_plugin_odrs_fetch_for_app (GsPlugin *plugin, GsApp *app, GError **error)
 
        /* look in the cache */
        cachefn_basename = g_strdup_printf ("%s.json", gs_app_get_id (app));
-       cachefn = gs_utils_get_cache_filename ("reviews",
+       cachefn = gs_utils_get_cache_filename ("odrs",
                                               cachefn_basename,
                                               GS_UTILS_CACHE_FLAG_WRITEABLE,
                                               error);
@@ -807,7 +807,7 @@ gs_plugin_odrs_invalidate_cache (AsReview *review, GError **error)
        /* look in the cache */
        cachefn_basename = g_strdup_printf ("%s.json",
                                            as_review_get_metadata_item (review, "app_id"));
-       cachefn = gs_utils_get_cache_filename ("reviews",
+       cachefn = gs_utils_get_cache_filename ("odrs",
                                               cachefn_basename,
                                               GS_UTILS_CACHE_FLAG_WRITEABLE,
                                               error);
diff --git a/plugins/shell-extensions/gs-plugin-shell-extensions.c 
b/plugins/shell-extensions/gs-plugin-shell-extensions.c
index a7cbf6b..3327268 100644
--- a/plugins/shell-extensions/gs-plugin-shell-extensions.c
+++ b/plugins/shell-extensions/gs-plugin-shell-extensions.c
@@ -644,7 +644,7 @@ gs_plugin_shell_extensions_get_apps (GsPlugin *plugin,
        g_autoptr(GsApp) app_dl = gs_app_new (gs_plugin_get_name (plugin));
 
        /* look in the cache */
-       cachefn = gs_utils_get_cache_filename ("extensions",
+       cachefn = gs_utils_get_cache_filename ("shell-extensions",
                                               "gnome.json",
                                               GS_UTILS_CACHE_FLAG_WRITEABLE,
                                               error);


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