Skip to content
Snippets Groups Projects
Commit 920a648b authored by Sébastien Blin's avatar Sébastien Blin
Browse files

message_engine: create directory if necessary

Change-Id: I155f5182fbb370116e020151dc3c154cee66c814
GitLab: #407
parent cbca4abe
Branches
Tags
No related merge requests found
...@@ -36,7 +36,11 @@ namespace im { ...@@ -36,7 +36,11 @@ namespace im {
MessageEngine::MessageEngine(SIPAccountBase& acc, const std::string& path) MessageEngine::MessageEngine(SIPAccountBase& acc, const std::string& path)
: account_(acc) : account_(acc)
, savePath_(path) , savePath_(path)
{} {
auto found = savePath_.find_last_of(DIR_SEPARATOR_CH);
auto dir = savePath_.substr(0, found);
fileutils::check_dir(dir.c_str());
}
MessageToken MessageToken
MessageEngine::sendMessage(const std::string& to, const std::map<std::string, std::string>& payloads) MessageEngine::sendMessage(const std::string& to, const std::map<std::string, std::string>& payloads)
...@@ -201,6 +205,7 @@ MessageEngine::load() ...@@ -201,6 +205,7 @@ MessageEngine::load()
std::ifstream file; std::ifstream file;
file.exceptions(std::ifstream::failbit | std::ifstream::badbit); file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
fileutils::openStream(file, savePath_); fileutils::openStream(file, savePath_);
if (file.is_open())
file >> root; file >> root;
} }
std::lock_guard<std::mutex> lock(messagesMutex_); std::lock_guard<std::mutex> lock(messagesMutex_);
...@@ -293,6 +298,7 @@ MessageEngine::save_() const ...@@ -293,6 +298,7 @@ MessageEngine::save_() const
std::ofstream file; std::ofstream file;
file.exceptions(std::ifstream::failbit | std::ifstream::badbit); file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
fileutils::openStream(file, path, std::ios::trunc); fileutils::openStream(file, path, std::ios::trunc);
if (file.is_open())
writer->write(root, &file); writer->write(root, &file);
} catch (const std::exception& e) { } catch (const std::exception& e) {
JAMI_ERR("[Account %s] Couldn't save messages to %s: %s", JAMI_ERR("[Account %s] Couldn't save messages to %s: %s",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment