From 1c984265366ed68f296a1c5aed6b47a23220334a Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 22 Jan 2021 03:18:36 +0100 Subject: Fix tags --- src/Cache.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/Cache.cpp') diff --git a/src/Cache.cpp b/src/Cache.cpp index e2aecca2..7e25fed2 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -1235,11 +1235,11 @@ Cache::saveState(const mtx::responses::Sync &res) updatedInfo.avatar_url = getRoomAvatarUrl(txn, statesdb, membersdb).toStdString(); updatedInfo.version = getRoomVersion(txn, statesdb).toStdString(); + bool has_new_tags = false; // Process the account_data associated with this room if (!room.second.account_data.events.empty()) { auto accountDataDb = getAccountDataDb(txn, room.first); - bool has_new_tags = false; for (const auto &evt : room.second.account_data.events) { std::visit( [&txn, &accountDataDb](const auto &event) { @@ -1266,21 +1266,21 @@ Cache::saveState(const mtx::responses::Sync &res) nhlog::db()->debug("Fully read: {}", fr->content.event_id); } } - if (!has_new_tags) { - // retrieve the old tags, they haven't changed - lmdb::val data; - if (lmdb::dbi_get(txn, roomsDb_, lmdb::val(room.first), data)) { - try { - RoomInfo tmp = json::parse( - std::string_view(data.data(), data.size())); - updatedInfo.tags = tmp.tags; - } catch (const json::exception &e) { - nhlog::db()->warn( - "failed to parse room info: room_id ({}), {}: {}", - room.first, - std::string(data.data(), data.size()), - e.what()); - } + } + if (!has_new_tags) { + // retrieve the old tags, they haven't changed + lmdb::val data; + if (lmdb::dbi_get(txn, roomsDb_, lmdb::val(room.first), data)) { + try { + RoomInfo tmp = + json::parse(std::string_view(data.data(), data.size())); + updatedInfo.tags = tmp.tags; + } catch (const json::exception &e) { + nhlog::db()->warn( + "failed to parse room info: room_id ({}), {}: {}", + room.first, + std::string(data.data(), data.size()), + e.what()); } } } -- cgit 1.5.1 From 0e628290af2bd3cf35c322e22bf17bad59187ecf Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Tue, 19 Jan 2021 19:44:22 +0100 Subject: Write database to the DataLocation --- src/Cache.cpp | 24 +++++++++++++++++++++++- src/main.cpp | 7 ++++--- 2 files changed, 27 insertions(+), 4 deletions(-) (limited to 'src/Cache.cpp') diff --git a/src/Cache.cpp b/src/Cache.cpp index 7e25fed2..6b3067db 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -169,13 +169,35 @@ Cache::setup() nhlog::db()->debug("setting up cache"); + // Previous location of the cache directory + auto oldCache = QString("%1/%2%3") + .arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)) + .arg(QString::fromUtf8(localUserId_.toUtf8().toHex())) + .arg(QString::fromUtf8(settings->profile().toUtf8().toHex())); + cacheDirectory_ = QString("%1/%2%3") - .arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)) + .arg(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)) .arg(QString::fromUtf8(localUserId_.toUtf8().toHex())) .arg(QString::fromUtf8(settings->profile().toUtf8().toHex())); bool isInitial = !QFile::exists(cacheDirectory_); + // NOTE: If both cache directories exist it's better to do nothing: it + // could mean a previous migration failed or was interrupted. + bool needsMigration = isInitial && QFile::exists(oldCache); + + if (needsMigration) { + nhlog::db()->info("found old state directory, migrating"); + if (!QDir().rename(oldCache, cacheDirectory_)) { + throw std::runtime_error(("Unable to migrate the old state directory (" + + oldCache + ") to the new location (" + + cacheDirectory_ + ")") + .toStdString() + .c_str()); + } + nhlog::db()->info("completed state migration"); + } + env_ = lmdb::env::create(); env_.set_mapsize(DB_SIZE); env_.set_max_dbs(MAX_DBS); diff --git a/src/main.cpp b/src/main.cpp index b1dfa9f6..a890a6fd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -93,9 +93,9 @@ screenCenter(int width, int height) } void -createCacheDirectory() +createStandardDirectory(QStandardPaths::StandardLocation path) { - auto dir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); + auto dir = QStandardPaths::writableLocation(path); if (!QDir().mkpath(dir)) { throw std::runtime_error( @@ -188,7 +188,8 @@ main(int argc, char *argv[]) http::init(); - createCacheDirectory(); + createStandardDirectory(QStandardPaths::CacheLocation); + createStandardDirectory(QStandardPaths::AppDataLocation); registerSignalHandlers(); -- cgit 1.5.1 From 6313ecb7d4e67d0b89ef55f6a1991bc86b4093ae Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 25 Jan 2021 15:28:35 +0100 Subject: Treat empty secrets as no secret --- src/Cache.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/Cache.cpp') diff --git a/src/Cache.cpp b/src/Cache.cpp index 6b3067db..de377f49 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -661,6 +661,10 @@ Cache::secret(const std::string &name) "Restoring secret '{}' failed: {}", name, job.errorString().toStdString()); return std::nullopt; } + if (secret.isEmpty()) { + nhlog::db()->debug("Restored empty secret '{}'.", name); + return std::nullopt; + } return secret.toStdString(); } -- cgit 1.5.1 From 0b5269bfc0f7d7ea551c3e4fea15944e780c75ad Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 25 Jan 2021 17:06:27 +0100 Subject: Reload the timeline after key import --- src/Cache.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Cache.cpp') diff --git a/src/Cache.cpp b/src/Cache.cpp index de377f49..3f2bf73a 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -327,6 +327,7 @@ Cache::importSessionKeys(const mtx::crypto::ExportedSessionKeys &keys) auto exported_session = mtx::crypto::import_session(s.session_key); saveInboundMegolmSession(index, std::move(exported_session)); + ChatPage::instance()->receivedSessionKey(index.room_id, index.session_id); } } -- cgit 1.5.1