[gnome-software] trivial: Actually create the directory in gs_utils_get_cachedir()
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] trivial: Actually create the directory in gs_utils_get_cachedir()
- Date: Tue, 9 Feb 2016 17:22:42 +0000 (UTC)
commit 93eed8b1a1912bb31987cb26fba1c7eb0a942780
Author: Richard Hughes <richard hughsie com>
Date: Tue Feb 9 16:44:32 2016 +0000
trivial: Actually create the directory in gs_utils_get_cachedir()
src/gs-screenshot-image.c | 2 +-
src/gs-utils.c | 17 ++++++++++++++---
src/gs-utils.h | 3 ++-
src/plugins/gs-plugin-appstream.c | 2 +-
src/plugins/gs-plugin-fwupd.c | 11 ++---------
5 files changed, 20 insertions(+), 15 deletions(-)
---
diff --git a/src/gs-screenshot-image.c b/src/gs-screenshot-image.c
index 041c1c7..3cd176e 100644
--- a/src/gs-screenshot-image.c
+++ b/src/gs-screenshot-image.c
@@ -386,7 +386,7 @@ gs_screenshot_image_load_async (GsScreenshotImage *ssimg,
} else {
sizedir = g_strdup_printf ("%ux%u", ssimg->width * ssimg->scale, ssimg->height *
ssimg->scale);
}
- cachedir = gs_utils_get_cachedir ("screenshots");
+ cachedir = gs_utils_get_cachedir ("screenshots", NULL);
cachedir_full = g_build_filename (cachedir, sizedir, NULL);
rc = g_mkdir_with_parents (cachedir_full, 0700);
if (rc != 0) {
diff --git a/src/gs-utils.c b/src/gs-utils.c
index b554137..f972465 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -454,13 +454,24 @@ gs_user_agent (void)
* gs_utils_get_cachedir:
**/
gchar *
-gs_utils_get_cachedir (const gchar *kind)
+gs_utils_get_cachedir (const gchar *kind, GError **error)
{
g_autofree gchar *vername = NULL;
+ g_autofree gchar *cachedir = NULL;
g_auto(GStrv) version = g_strsplit (VERSION, ".", 3);
+ g_autoptr(GFile) cachedir_file = NULL;
+
+ /* create the cachedir in a per-release location, creating
+ * if it does not already exist */
vername = g_strdup_printf ("%s.%s", version[0], version[1]);
- return g_build_filename (g_get_user_cache_dir (),
- "gnome-software", vername, kind, NULL);
+ cachedir = g_build_filename (g_get_user_cache_dir (),
+ "gnome-software", vername, kind, NULL);
+ cachedir_file = g_file_new_for_path (cachedir);
+ if (!g_file_query_exists (cachedir_file, NULL) &&
+ !g_file_make_directory_with_parents (cachedir_file, NULL, error))
+ return NULL;
+
+ return g_steal_pointer (&cachedir);
}
/* vim: set noexpandtab: */
diff --git a/src/gs-utils.h b/src/gs-utils.h
index 1032abc..22a8ba5 100644
--- a/src/gs-utils.h
+++ b/src/gs-utils.h
@@ -60,7 +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);
+gchar *gs_utils_get_cachedir (const gchar *kind,
+ GError **error);
G_END_DECLS
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 66c1dd7..edd735a 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -263,7 +263,7 @@ gs_plugin_refine_item_pixbuf (GsPlugin *plugin, GsApp *app, AsApp *item)
case AS_ICON_KIND_REMOTE:
gs_app_set_icon (app, icon);
if (as_icon_get_filename (icon) == NULL) {
- cachedir = gs_utils_get_cachedir ("icons");
+ cachedir = gs_utils_get_cachedir ("icons", NULL);
fn = g_build_filename (cachedir, as_icon_get_name (icon), NULL);
as_icon_set_filename (icon, fn);
as_icon_set_prefix (icon, cachedir);
diff --git a/src/plugins/gs-plugin-fwupd.c b/src/plugins/gs-plugin-fwupd.c
index c52c2bb..9b36314 100644
--- a/src/plugins/gs-plugin-fwupd.c
+++ b/src/plugins/gs-plugin-fwupd.c
@@ -126,7 +126,6 @@ gs_plugin_fwupd_changed_cb (GDBusProxy *proxy,
static gboolean
gs_plugin_startup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
{
- gint rc;
gsize len;
g_autoptr(GError) error_local = NULL;
g_autofree gchar *data = NULL;
@@ -155,15 +154,9 @@ gs_plugin_startup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
G_CALLBACK (gs_plugin_fwupd_changed_cb), plugin);
/* create the cache location */
- 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,
- GS_PLUGIN_ERROR,
- GS_PLUGIN_ERROR_FAILED,
- "Could not create firmware cache");
+ plugin->priv->cachedir = gs_utils_get_cachedir ("firmware", error);
+ if (plugin->priv->cachedir == NULL)
return FALSE;
- }
/* get the hash of the previously downloaded file */
plugin->priv->lvfs_sig_fn = g_build_filename (plugin->priv->cachedir,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]