[gnome-software] Use versioned user cache directories
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Use versioned user cache directories
- Date: Tue, 2 Feb 2016 10:41:30 +0000 (UTC)
commit a6b4b3ba024ac719f032ef435426ecad66343c01
Author: Richard Hughes <richard hughsie com>
Date: Tue Feb 2 10:40:07 2016 +0000
Use versioned user cache directories
If upstream changes the screenshot or remote icon content without changing the
URL in the AppData file then we never re-download the new content.
We also don't want to redownload this every time as well, so just invalidate
all the cached content when we change the minor version of gnome-software,
e.g. from 3-16 to 3-18.
src/gs-screenshot-image.c | 40 +++++++++++-------------------------
src/gs-screenshot-image.h | 2 -
src/gs-shell-details.c | 6 -----
src/gs-utils.c | 13 ++++++++++++
src/gs-utils.h | 2 +
src/plugins/gs-plugin-appstream.c | 12 ++++------
src/plugins/gs-plugin-fwupd.c | 5 +---
7 files changed, 33 insertions(+), 47 deletions(-)
---
diff --git a/src/gs-screenshot-image.c b/src/gs-screenshot-image.c
index 7c015b1..041c1c7 100644
--- a/src/gs-screenshot-image.c
+++ b/src/gs-screenshot-image.c
@@ -44,7 +44,6 @@ struct _GsScreenshotImage
GtkWidget *label_error;
SoupSession *session;
SoupMessage *message;
- gchar *cachedir;
gchar *filename;
const gchar *current_image;
gboolean use_desktop_background;
@@ -282,16 +281,6 @@ gs_screenshot_image_complete_cb (SoupSession *session,
}
/**
- * gs_screenshot_image_set_cachedir:
- **/
-void
-gs_screenshot_image_set_cachedir (GsScreenshotImage *ssimg, const gchar *cachedir)
-{
- g_free (ssimg->cachedir);
- ssimg->cachedir = g_strdup (cachedir);
-}
-
-/**
* gs_screenshot_image_set_screenshot:
**/
void
@@ -360,8 +349,9 @@ gs_screenshot_image_load_async (GsScreenshotImage *ssimg,
const gchar *url;
gint rc;
g_autofree gchar *basename = NULL;
- g_autofree gchar *cachedir2 = NULL;
+ g_autofree gchar *cachedir_full = NULL;
g_autofree gchar *cachedir = NULL;
+ g_autofree gchar *cachedir_thumb = NULL;
g_autofree gchar *sizedir = NULL;
g_return_if_fail (GS_IS_SCREENSHOT_IMAGE (ssimg));
@@ -396,12 +386,9 @@ gs_screenshot_image_load_async (GsScreenshotImage *ssimg,
} else {
sizedir = g_strdup_printf ("%ux%u", ssimg->width * ssimg->scale, ssimg->height *
ssimg->scale);
}
- cachedir = g_build_filename (ssimg->cachedir,
- "gnome-software",
- "screenshots",
- sizedir,
- NULL);
- rc = g_mkdir_with_parents (cachedir, 0700);
+ cachedir = gs_utils_get_cachedir ("screenshots");
+ cachedir_full = g_build_filename (cachedir, sizedir, NULL);
+ rc = g_mkdir_with_parents (cachedir_full, 0700);
if (rc != 0) {
/* TRANSLATORS: this is when we try create the cache directory
* but we were out of space or permission was denied */
@@ -410,7 +397,7 @@ gs_screenshot_image_load_async (GsScreenshotImage *ssimg,
}
/* does local file already exist */
- ssimg->filename = g_build_filename (cachedir, basename, NULL);
+ ssimg->filename = g_build_filename (cachedir_full, basename, NULL);
if (g_file_test (ssimg->filename, G_FILE_TEST_EXISTS)) {
as_screenshot_show_image (ssimg);
return;
@@ -419,14 +406,12 @@ gs_screenshot_image_load_async (GsScreenshotImage *ssimg,
/* can we load a blurred smaller version of this straight away */
if (ssimg->width > AS_IMAGE_THUMBNAIL_WIDTH &&
ssimg->height > AS_IMAGE_THUMBNAIL_HEIGHT) {
- cachedir2 = g_build_filename (ssimg->cachedir,
- "gnome-software",
- "screenshots",
- "112x63",
- basename,
- NULL);
- if (g_file_test (cachedir2, G_FILE_TEST_EXISTS))
- gs_screenshot_image_show_blurred (ssimg, cachedir2);
+ cachedir_thumb = g_build_filename (cachedir,
+ "112x63",
+ basename,
+ NULL);
+ if (g_file_test (cachedir_thumb, G_FILE_TEST_EXISTS))
+ gs_screenshot_image_show_blurred (ssimg, cachedir_thumb);
}
/* download file */
@@ -481,7 +466,6 @@ gs_screenshot_image_destroy (GtkWidget *widget)
g_clear_object (&ssimg->screenshot);
g_clear_object (&ssimg->session);
- g_clear_pointer (&ssimg->cachedir, g_free);
g_clear_pointer (&ssimg->filename, g_free);
GTK_WIDGET_CLASS (gs_screenshot_image_parent_class)->destroy (widget);
diff --git a/src/gs-screenshot-image.h b/src/gs-screenshot-image.h
index e9e2889..113327f 100644
--- a/src/gs-screenshot-image.h
+++ b/src/gs-screenshot-image.h
@@ -38,8 +38,6 @@ GtkWidget *gs_screenshot_image_new (SoupSession *session);
AsScreenshot *gs_screenshot_image_get_screenshot (GsScreenshotImage *ssimg);
void gs_screenshot_image_set_screenshot (GsScreenshotImage *ssimg,
AsScreenshot *screenshot);
-void gs_screenshot_image_set_cachedir (GsScreenshotImage *ssimg,
- const gchar *cachedir);
void gs_screenshot_image_set_size (GsScreenshotImage *ssimg,
guint width,
guint height);
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 64c04d9..6a38501 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -432,8 +432,6 @@ gs_shell_details_refresh_screenshots (GsShellDetails *self)
/* set images */
ssimg = gs_screenshot_image_new (self->session);
- gs_screenshot_image_set_cachedir (GS_SCREENSHOT_IMAGE (ssimg),
- g_get_user_cache_dir ());
gs_screenshot_image_set_screenshot (GS_SCREENSHOT_IMAGE (ssimg), ss);
gs_screenshot_image_set_size (GS_SCREENSHOT_IMAGE (ssimg),
640,
@@ -459,8 +457,6 @@ gs_shell_details_refresh_screenshots (GsShellDetails *self)
ss = g_ptr_array_index (screenshots, 0);
ssimg = gs_screenshot_image_new (self->session);
gtk_widget_set_can_focus (gtk_bin_get_child (GTK_BIN (ssimg)), FALSE);
- gs_screenshot_image_set_cachedir (GS_SCREENSHOT_IMAGE (ssimg),
- g_get_user_cache_dir ());
gs_screenshot_image_set_screenshot (GS_SCREENSHOT_IMAGE (ssimg), ss);
/* use a slightly larger screenshot if it's the only screenshot */
@@ -489,8 +485,6 @@ gs_shell_details_refresh_screenshots (GsShellDetails *self)
for (i = 0; i < screenshots->len; i++) {
ss = g_ptr_array_index (screenshots, i);
ssimg = gs_screenshot_image_new (self->session);
- gs_screenshot_image_set_cachedir (GS_SCREENSHOT_IMAGE (ssimg),
- g_get_user_cache_dir ());
gs_screenshot_image_set_screenshot (GS_SCREENSHOT_IMAGE (ssimg), ss);
gs_screenshot_image_set_size (GS_SCREENSHOT_IMAGE (ssimg),
AS_IMAGE_THUMBNAIL_WIDTH,
diff --git a/src/gs-utils.c b/src/gs-utils.c
index 81721f1..b554137 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -450,4 +450,17 @@ gs_user_agent (void)
return PACKAGE_NAME "/" PACKAGE_VERSION;
}
+/**
+ * gs_utils_get_cachedir:
+ **/
+gchar *
+gs_utils_get_cachedir (const gchar *kind)
+{
+ g_autofree gchar *vername = NULL;
+ g_auto(GStrv) version = g_strsplit (VERSION, ".", 3);
+ vername = g_strdup_printf ("%s.%s", version[0], version[1]);
+ return g_build_filename (g_get_user_cache_dir (),
+ "gnome-software", vername, kind, NULL);
+}
+
/* vim: set noexpandtab: */
diff --git a/src/gs-utils.h b/src/gs-utils.h
index 7fd038b..1032abc 100644
--- a/src/gs-utils.h
+++ b/src/gs-utils.h
@@ -60,6 +60,8 @@ void gs_image_set_from_pixbuf (GtkImage *image,
const GdkPixbuf *pixbuf);
const gchar *gs_user_agent (void);
+gchar *gs_utils_get_cachedir (const gchar *kind);
+
G_END_DECLS
#endif /* __GS_UTILS_H */
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index a140970..66c1dd7 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -23,6 +23,7 @@
#include <glib/gi18n.h>
#include <appstream-glib.h>
+#include <gs-utils.h>
#include <gs-plugin.h>
#include <gs-plugin-loader.h>
@@ -255,20 +256,17 @@ gs_plugin_refine_item_pixbuf (GsPlugin *plugin, GsApp *app, AsApp *item)
gboolean ret;
g_autoptr(GError) error = NULL;
g_autofree gchar *fn = NULL;
- g_autofree gchar *path = NULL;
+ g_autofree gchar *cachedir = NULL;
icon = as_app_get_icon_default (item);
switch (as_icon_get_kind (icon)) {
case AS_ICON_KIND_REMOTE:
gs_app_set_icon (app, icon);
if (as_icon_get_filename (icon) == NULL) {
- path = g_build_filename (g_get_user_data_dir (),
- "gnome-software",
- "icons",
- NULL);
- fn = g_build_filename (path, as_icon_get_name (icon), NULL);
+ cachedir = gs_utils_get_cachedir ("icons");
+ fn = g_build_filename (cachedir, as_icon_get_name (icon), NULL);
as_icon_set_filename (icon, fn);
- as_icon_set_prefix (icon, path);
+ as_icon_set_prefix (icon, cachedir);
}
if (g_file_test (fn, G_FILE_TEST_EXISTS)) {
as_icon_set_kind (icon, AS_ICON_KIND_LOCAL);
diff --git a/src/plugins/gs-plugin-fwupd.c b/src/plugins/gs-plugin-fwupd.c
index ccc83f4..c52c2bb 100644
--- a/src/plugins/gs-plugin-fwupd.c
+++ b/src/plugins/gs-plugin-fwupd.c
@@ -155,10 +155,7 @@ gs_plugin_startup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
G_CALLBACK (gs_plugin_fwupd_changed_cb), plugin);
/* create the cache location */
- plugin->priv->cachedir = g_build_filename (g_get_user_cache_dir (),
- "gnome-software",
- "firmware",
- NULL);
+ plugin->priv->cachedir = gs_utils_get_cachedir ("firmware");
rc = g_mkdir_with_parents (plugin->priv->cachedir, 0700);
if (rc != 0) {
g_set_error_literal (error,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]