From 1209744b38da0252731812d4cc5371be960fb3c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Wed, 24 Sep 2014 17:08:44 +0200 Subject: [PATCH] use the default cache location on ios to avoid writing to unwritable file system locations --- common/ios.mm | 19 +++++++++++++++++++ include/mbgl/platform/platform.hpp | 3 +++ include/mbgl/storage/file_source.hpp | 2 +- ios/mapbox-gl-cocoa | 2 +- src/map/map.cpp | 2 +- src/storage/file_source.cpp | 4 ++-- 6 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 common/ios.mm diff --git a/common/ios.mm b/common/ios.mm new file mode 100644 index 000000000..1076343e2 --- /dev/null +++ b/common/ios.mm @@ -0,0 +1,19 @@ +#import + +#include + +namespace mbgl { +namespace platform { + +// Returns the path to the default cache database on this system. +std::string defaultCacheDatabase() { + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); + NSString *libraryDirectory = [paths objectAtIndex:0]; + return [[libraryDirectory stringByAppendingPathComponent:@"cache.db"] UTF8String]; +} + +} +} + + +// Returns the path to the default cache database on this system. diff --git a/include/mbgl/platform/platform.hpp b/include/mbgl/platform/platform.hpp index 6356d81bb..b7107bb9c 100644 --- a/include/mbgl/platform/platform.hpp +++ b/include/mbgl/platform/platform.hpp @@ -17,6 +17,9 @@ std::string uppercase(const std::string &string); // Lowercase a string, potentially using platform-specific routines. std::string lowercase(const std::string &string); +// Returns the path to the default cache database on this system. +std::string defaultCacheDatabase(); + // Shows an alpha image with the specified dimensions in a named window. void show_debug_image(std::string name, const char *data, size_t width, size_t height); diff --git a/include/mbgl/storage/file_source.hpp b/include/mbgl/storage/file_source.hpp index 06d416d0c..5933aea48 100644 --- a/include/mbgl/storage/file_source.hpp +++ b/include/mbgl/storage/file_source.hpp @@ -24,7 +24,7 @@ private: FileSource& operator=(FileSource &&) = delete; public: - FileSource(uv_loop_t *loop); + FileSource(uv_loop_t *loop, const std::string &path); ~FileSource(); public: diff --git a/ios/mapbox-gl-cocoa b/ios/mapbox-gl-cocoa index f3829151a..c22686c5b 160000 --- a/ios/mapbox-gl-cocoa +++ b/ios/mapbox-gl-cocoa @@ -1 +1 @@ -Subproject commit f3829151abb7582568433c159eb3a7e50a7ab7d7 +Subproject commit c22686c5bc9f1cafd37b684bab31b70a38ed6494 diff --git a/src/map/map.cpp b/src/map/map.cpp index eabf7b8fe..05c56c10e 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -571,7 +571,7 @@ void Map::prepare() { view.make_active(); if (!fileSource) { - fileSource = std::make_shared(**loop); + fileSource = std::make_shared(**loop, platform::defaultCacheDatabase()); glyphStore = std::make_shared(fileSource); } diff --git a/src/storage/file_source.cpp b/src/storage/file_source.cpp index ef2b036e5..52a3872cb 100644 --- a/src/storage/file_source.cpp +++ b/src/storage/file_source.cpp @@ -8,9 +8,9 @@ namespace mbgl { -FileSource::FileSource(uv_loop_t *loop_) +FileSource::FileSource(uv_loop_t *loop_, const std::string &path) : thread_id(uv_thread_self()), - store(util::ptr(new SQLiteStore(loop_, "cache.db"))), + store(util::ptr(new SQLiteStore(loop_, path))), loop(loop_), queue(new uv_messenger_t) {