diff options
-rw-r--r-- | 3party/succinct/mapper.hpp | 4 | ||||
-rw-r--r-- | coding/writer.hpp | 1 | ||||
-rw-r--r-- | platform/platform.cpp | 6 | ||||
-rw-r--r-- | platform/platform.hpp | 12 | ||||
-rw-r--r-- | platform/platform_android.cpp | 6 | ||||
-rw-r--r-- | platform/platform_ios.mm | 6 | ||||
-rw-r--r-- | platform/platform_mac.mm | 2 | ||||
-rw-r--r-- | platform/platform_qt.cpp | 10 |
8 files changed, 38 insertions, 9 deletions
diff --git a/3party/succinct/mapper.hpp b/3party/succinct/mapper.hpp index b8c84fb645..a39873307d 100644 --- a/3party/succinct/mapper.hpp +++ b/3party/succinct/mapper.hpp @@ -265,7 +265,9 @@ namespace succinct { namespace mapper { template <typename T> size_t freeze(T& val, const char* filename, uint64_t flags = 0, const char* friendly_name = "<TOP>") { - std::ofstream fout(filename, std::ios::binary); + std::ofstream fout; + fout.exceptions(std::ifstream::failbit); + fout.open(filename, std::ios::binary); return freeze(val, fout, flags, friendly_name); } diff --git a/coding/writer.hpp b/coding/writer.hpp index debdb41708..fcc7208a9f 100644 --- a/coding/writer.hpp +++ b/coding/writer.hpp @@ -18,6 +18,7 @@ public: DECLARE_EXCEPTION(WriteException, Exception); DECLARE_EXCEPTION(PosException, Exception); DECLARE_EXCEPTION(SeekException, Exception); + DECLARE_EXCEPTION(CreateDirException, Exception); virtual ~Writer() {} virtual void Seek(int64_t pos) = 0; diff --git a/platform/platform.cpp b/platform/platform.cpp index 87504f8108..b83001ba34 100644 --- a/platform/platform.cpp +++ b/platform/platform.cpp @@ -3,6 +3,7 @@ #include "../coding/sha2.hpp" #include "../coding/base64.hpp" #include "../coding/file_name_utils.hpp" +#include "../coding/writer.hpp" #include "../base/logging.hpp" @@ -99,7 +100,10 @@ string Platform::WritablePathForCountryIndexes(string const & mwmName) const { string dir = WritableDir() + mwmName + my::GetNativeSeparator(); if (!IsFileExistsByFullPath(dir)) - MkDir(dir); + if (MkDir(dir) != Platform::ERR_OK) + { + MYTHROW(Writer::CreateDirException, ("Can't create directory:", dir)); + } return dir; } diff --git a/platform/platform.hpp b/platform/platform.hpp index 82208d1402..a66a9036e9 100644 --- a/platform/platform.hpp +++ b/platform/platform.hpp @@ -18,6 +18,13 @@ DECLARE_EXCEPTION(NotImplementedException, RootException); class Platform { +public: + enum EError + { + ERR_OK = 0, + ERR_UNKNOWN = 1 + }; + protected: /// Usually read-only directory for application resources string m_resourcesDir; @@ -60,7 +67,8 @@ public: string WritableDir() const { return m_writableDir; } /// @return full path to file in user's writable directory string WritablePathForFile(string const & file) const { return WritableDir() + file; } - /// @return full path to indexes directory for country file. Creates directory if it's not exists. + /// @return full path to indexes directory for country file. + /// Creates directory if it's not exists. Throw Writer::CreateDirException if can't create. string WritablePathForCountryIndexes(string const & mwmName) const; /// @return generate full path to index based on mwmName and index extension string GetIndexFileName(string const & mwmName, string const & extension) const; @@ -69,7 +77,7 @@ public: string ResourcesDir() const { return m_resourcesDir; } /// Creates directory at filesystem - void MkDir(string const & dirName) const; + EError MkDir(string const & dirName) const; /// @TODO create join method for string concatenation diff --git a/platform/platform_android.cpp b/platform/platform_android.cpp index 6e83a93c5b..90ece32cd0 100644 --- a/platform/platform_android.cpp +++ b/platform/platform_android.cpp @@ -244,10 +244,14 @@ bool Platform::GetFileSizeByName(string const & fileName, uint64_t & size) const } } -void Platform::MkDir(string const & dirName) const +Platform::EError Platform::MkDir(string const & dirName) const { if (mkdir(dirName.c_str(), 0755)) + { LOG(LWARNING, ("Can't create directory: ", dirName)); + return Platform::ERR_UNKNOWN; + } + return Platform::ERR_OK; } namespace diff --git a/platform/platform_ios.mm b/platform/platform_ios.mm index 7ae95706f1..d30f3eb6fa 100644 --- a/platform/platform_ios.mm +++ b/platform/platform_ios.mm @@ -50,9 +50,11 @@ Platform::Platform() [pool release]; } -void Platform::MkDir(string const & dirName) const +Platform::EError Platform::MkDir(string const & dirName) const { - ::mkdir(dirName.c_str(), 0755); + if (::mkdir(dirName.c_str(), 0755)) + return Platform::ERR_UNKNOWN; + return Platform::ERR_OK; } void Platform::GetFilesByRegExp(string const & directory, string const & regexp, FilesList & res) diff --git a/platform/platform_mac.mm b/platform/platform_mac.mm index fcbdc6d081..78c9bd3197 100644 --- a/platform/platform_mac.mm +++ b/platform/platform_mac.mm @@ -32,6 +32,8 @@ Platform::Platform() string const repoPath = bundlePath + "/../../../omim/data/"; if (IsFileExistsByFullPath(repoPath)) m_resourcesDir = repoPath; + else + m_resourcesDir = "./data/"; } m_writableDir = m_resourcesDir; } diff --git a/platform/platform_qt.cpp b/platform/platform_qt.cpp index 1fae77cdfe..5e11198333 100644 --- a/platform/platform_qt.cpp +++ b/platform/platform_qt.cpp @@ -3,6 +3,7 @@ #include "../coding/file_reader.hpp" +#include "../base/logging.hpp" #include "../base/regexp.hpp" #include "../std/target_os.hpp" @@ -56,9 +57,14 @@ int Platform::VideoMemoryLimit() const return 20 * 1024 * 1024; } -void Platform::MkDir(string const & dirName) const +Platform::EError Platform::MkDir(string const & dirName) const { - QDir().mkdir(dirName.c_str()); + if(!QDir().mkdir(dirName.c_str())) + { + LOG(LWARNING, ("Can't create directory: ", dirName)); + return Platform::ERR_UNKNOWN; + } + return Platform::ERR_OK; } |