From: Pierre-Luc Beaudoin Date: Sun, 31 May 2009 20:19:15 +0000 (-0400) Subject: Fix Bug 584390: Cache doesn't work on first run X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4df9b62c6ec3a285fcec005f5cf163e2d07cf75;p=libchamplain Fix Bug 584390: Cache doesn't work on first run It turns out that the ~/.cache/champlain didn't exist at the moment of the first cache request, resulting in a error when creating cache.db which would later result in more errors from SQLite preventing the cache from working. --- diff --git a/champlain/champlain-cache.c b/champlain/champlain-cache.c index 60d2425..4a6a34c 100644 --- a/champlain/champlain-cache.c +++ b/champlain/champlain-cache.c @@ -38,6 +38,7 @@ #include "champlain-enum-types.h" #include "champlain-private.h" +#include #include #include #include @@ -176,7 +177,7 @@ champlain_cache_class_init (ChamplainCacheClass *klass) static void champlain_cache_init (ChamplainCache *self) { - gchar *filename, *error_msg = NULL; + gchar *path, *filename, *error_msg = NULL; gint error; ChamplainCachePrivate *priv = GET_PRIVATE (self); @@ -191,9 +192,20 @@ champlain_cache_init (ChamplainCache *self) priv->stmt_select = NULL; priv->stmt_update = NULL; + /* Create, if needed, the cache's dirs */ + path = g_path_get_dirname (filename); + if (g_mkdir_with_parents (path, 0700) == -1) + { + if (errno != EEXIST) + { + g_warning ("Unable to create the image cache path '%s': %s", + path, g_strerror (errno)); + } + } + error = sqlite3_open_v2 (filename, &priv->data, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); - if (error != SQLITE_OK) + if (error == SQLITE_ERROR) { DEBUG ("Sqlite returned error %d when opening cache.db", error); goto cleanup; @@ -208,7 +220,7 @@ champlain_cache_init (ChamplainCache *self) if (error_msg != NULL) { DEBUG ("Creating table 'tiles' failed: %s", error_msg); - sqlite3_free (error_msg); + sqlite3_free (error_msg); goto cleanup; } @@ -218,8 +230,8 @@ champlain_cache_init (ChamplainCache *self) if (error != SQLITE_OK) { priv->stmt_select = NULL; - DEBUG ("Failed to prepare the select Etag statement, error: %s", - sqlite3_errmsg (priv->data)); + DEBUG ("Failed to prepare the select Etag statement, error:%d: %s", + error, sqlite3_errmsg (priv->data)); goto cleanup; } @@ -230,12 +242,13 @@ champlain_cache_init (ChamplainCache *self) { priv->stmt_update = NULL; DEBUG ("Failed to prepare the update popularity statement, error: %s", - sqlite3_errmsg (priv->data)); + sqlite3_errmsg (priv->data)); goto cleanup; } cleanup: g_free (filename); + g_free (path); } /** @@ -344,10 +357,9 @@ champlain_cache_fill_tile (ChamplainCache *self, g_object_unref (file); g_object_unref (info); - /* Retrieve etag */ sql_rc = sqlite3_bind_text (priv->stmt_select, 1, filename, -1, SQLITE_STATIC); - if (sql_rc != SQLITE_OK) + if (sql_rc == SQLITE_ERROR) { DEBUG ("Failed to prepare the SQL query for finding the Etag of '%s', error: %s", filename, sqlite3_errmsg (priv->data)); @@ -365,10 +377,10 @@ champlain_cache_fill_tile (ChamplainCache *self, DEBUG ("'%s' does't have an etag", filename); } - else + else if (sql_rc == SQLITE_ERROR) { - DEBUG ("Failed to finding the Etag of '%s', error: %s", - filename, sqlite3_errmsg (priv->data)); + DEBUG ("Failed to finding the Etag of '%s', %d error: %s", + filename, sql_rc, sqlite3_errmsg (priv->data)); goto cleanup; } diff --git a/champlain/champlain-network-map-source.c b/champlain/champlain-network-map-source.c index efe712b..4e2bb40 100644 --- a/champlain/champlain-network-map-source.c +++ b/champlain/champlain-network-map-source.c @@ -454,7 +454,7 @@ file_loaded_cb (SoupSession *session, DEBUG ("Unable to download tile %d, %d: %s", champlain_tile_get_x (tile), champlain_tile_get_y (tile), - soup_status_get_phrase(msg->status_code)); + soup_status_get_phrase (msg->status_code)); create_error_tile (tile); goto finish; }