mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-07 22:02:12 +08:00
namedirectory: catch parsing errors
Change-Id: Ia92378315f88051de76311d23156c1eb85c07770
This commit is contained in:
@ -476,6 +476,10 @@ NameDirectory::saveCache()
|
||||
dhtnet::fileutils::recursive_mkdir(fileutils::get_cache_dir() / CACHE_DIRECTORY);
|
||||
std::lock_guard lock(dhtnet::fileutils::getFileLock(cachePath_));
|
||||
std::ofstream file(cachePath_, std::ios::trunc | std::ios::binary);
|
||||
if (!file.is_open()) {
|
||||
JAMI_ERROR("Unable to save cache to {}", cachePath_);
|
||||
return;
|
||||
}
|
||||
{
|
||||
std::lock_guard l(cacheLock_);
|
||||
msgpack::pack(file, nameCache_);
|
||||
@ -505,13 +509,20 @@ NameDirectory::loadCache()
|
||||
}
|
||||
}
|
||||
|
||||
// load values
|
||||
std::lock_guard l(cacheLock_);
|
||||
msgpack::object_handle oh;
|
||||
if (pac.next(oh))
|
||||
oh.get().convert(nameCache_);
|
||||
for (const auto& m : nameCache_)
|
||||
addrCache_.emplace(m.second.second, m.second);
|
||||
try {
|
||||
// load values
|
||||
std::lock_guard l(cacheLock_);
|
||||
msgpack::object_handle oh;
|
||||
if (pac.next(oh))
|
||||
oh.get().convert(nameCache_);
|
||||
for (const auto& m : nameCache_)
|
||||
addrCache_.emplace(m.second.second, m.second);
|
||||
} catch (const msgpack::parse_error& e) {
|
||||
JAMI_ERROR("Error when parsing msgpack object: {}", e.what());
|
||||
} catch (const std::bad_cast& e) {
|
||||
JAMI_ERROR("Error when loading cache: {}", e.what());
|
||||
}
|
||||
|
||||
JAMI_DEBUG("Loaded {:d} name-address mappings", nameCache_.size());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user