[libchamplain] Use default cache path when not specified.
- From: Pierre-Luc Beaudoin <plbeaudoin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libchamplain] Use default cache path when not specified.
- Date: Tue, 16 Feb 2010 21:28:53 +0000 (UTC)
commit 22d260e316fa422f3ef14e1c146cb04da38f6f60
Author: JiÅ?Ã Techet <techet gmail com>
Date: Sat Jan 30 21:40:50 2010 +0100
Use default cache path when not specified.
Signed-off-by: JiÅ?Ã Techet <techet gmail com>
champlain/champlain-file-cache.c | 37 ++++++++++++++++++++++++++++---------
1 files changed, 28 insertions(+), 9 deletions(-)
---
diff --git a/champlain/champlain-file-cache.c b/champlain/champlain-file-cache.c
index 3d492d0..788a55e 100644
--- a/champlain/champlain-file-cache.c
+++ b/champlain/champlain-file-cache.c
@@ -70,6 +70,7 @@ static gchar *get_filename (ChamplainFileCache *file_cache, ChamplainTile *tile)
static gboolean tile_is_expired (ChamplainFileCache *file_cache, ChamplainTile *tile);
static void delete_tile (ChamplainFileCache *file_cache, const gchar *filename);
static void delete_dir_recursive (GFile *parent);
+static gboolean create_cache_dir (const gchar *dir_name);
static void fill_tile (ChamplainMapSource *map_source,
ChamplainTile *tile);
@@ -198,6 +199,22 @@ champlain_file_cache_finalize (GObject *object)
G_OBJECT_CLASS (champlain_file_cache_parent_class)->finalize (object);
}
+static gboolean
+create_cache_dir (const gchar *dir_name)
+{
+ /* If needed, create the cache's dirs */
+ if (dir_name)
+ {
+ if (g_mkdir_with_parents (dir_name, 0700) == -1 && errno != EEXIST)
+ {
+ g_warning ("Unable to create the image cache path '%s': %s",
+ dir_name, g_strerror (errno));
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
static void
init_cache (ChamplainFileCache *file_cache)
{
@@ -208,19 +225,21 @@ init_cache (ChamplainFileCache *file_cache)
gint error;
g_print ("init! '%d'\n", champlain_tile_cache_get_persistent (tile_cache));
- /* If needed, create the cache's dirs */
- if (priv->cache_dir)
+
+ g_return_if_fail (create_cache_dir (priv->cache_dir));
+
+ if (champlain_tile_cache_get_persistent (tile_cache))
{
- if (g_mkdir_with_parents (priv->cache_dir, 0700) == -1 && errno != EEXIST)
+ if (priv->cache_dir)
+ priv->real_cache_dir = g_strdup (priv->cache_dir);
+ else
{
- g_warning ("Unable to create the image cache path '%s': %s",
- priv->cache_dir, g_strerror (errno));
- return;
+ priv->real_cache_dir = g_build_path (G_DIR_SEPARATOR_S,
+ g_get_user_cache_dir (),
+ "champlain", NULL);
+ g_return_if_fail (create_cache_dir (priv->real_cache_dir));
}
}
-
- if (champlain_tile_cache_get_persistent (tile_cache))
- priv->real_cache_dir = g_strdup (priv->cache_dir);
else
{
/* Create temporary directory for non-persistent caches */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]