aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTobias Fella <fella@posteo.de>2021-11-15 21:57:59 +0100
committerTobias Fella <fella@posteo.de>2021-12-01 21:56:59 +0100
commit06facdb1179e2e6789d7263541294fb427f649e5 (patch)
treec4c2d238fae22d945fbaf713b0423d0a7d635244 /lib
parentcab1c772abaf380f30a504231fc06b070feb09ec (diff)
downloadlibquotient-06facdb1179e2e6789d7263541294fb427f649e5.tar.gz
libquotient-06facdb1179e2e6789d7263541294fb427f649e5.zip
Move non-cache data to a non-cache location
Diffstat (limited to 'lib')
-rw-r--r--lib/connection.cpp16
-rw-r--r--lib/connection.h2
-rw-r--r--lib/encryptionmanager.cpp4
-rw-r--r--lib/room.cpp5
4 files changed, 20 insertions, 7 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 20b4a113..cd4c9838 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -1949,7 +1949,7 @@ void Connection::Private::saveDevicesList()
QElapsedTimer et;
et.start();
- QFile outFile { q->stateCacheDir().filePath("deviceslist.json") };
+ QFile outFile { q->e2eeDataDir() + QStringLiteral("/deviceslist.json") };
if (!outFile.open(QFile::WriteOnly)) {
qCWarning(E2EE) << "Error opening" << outFile.fileName() << ":"
<< outFile.errorString();
@@ -1997,7 +1997,7 @@ void Connection::Private::saveDevicesList()
void Connection::Private::loadDevicesList()
{
- QFile file { q->stateCacheDir().filePath("deviceslist.json") };
+ QFile file { q->e2eeDataDir() + QStringLiteral("/deviceslist.json") };
if(!file.exists() || !file.open(QIODevice::ReadOnly)) {
qCDebug(E2EE) << "No devicesList cache exists. Creating new";
return;
@@ -2050,3 +2050,15 @@ void Connection::saveOlmAccount()
AccountSettings(d->data->userId()).setEncryptionAccountPickle(std::get<QByteArray>(pickle));
//TODO handle errors
}
+
+QString Connection::e2eeDataDir() const
+{
+ auto safeUserId = userId();
+ safeUserId.replace(':', '_');
+ const QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) % '/'
+ % safeUserId % '/';
+ QDir dir;
+ if (!dir.exists(path))
+ dir.mkpath(path);
+ return path;
+}
diff --git a/lib/connection.h b/lib/connection.h
index f5f06471..d1e3a992 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -399,6 +399,8 @@ public:
bool lazyLoading() const;
void setLazyLoading(bool newValue);
+ QString e2eeDataDir() const;
+
/*! Start a pre-created job object on this connection */
Q_INVOKABLE BaseJob* run(BaseJob* job,
RunningPolicy runningPolicy = ForegroundRequest);
diff --git a/lib/encryptionmanager.cpp b/lib/encryptionmanager.cpp
index 81c13e50..36cfb34c 100644
--- a/lib/encryptionmanager.cpp
+++ b/lib/encryptionmanager.cpp
@@ -51,7 +51,7 @@ public:
}
}
void loadSessions() {
- QFile file { static_cast<Connection *>(q->parent())->stateCacheDir().filePath("olmsessions.json") };
+ QFile file { static_cast<Connection *>(q->parent())->e2eeDataDir() + QStringLiteral("/olmsessions.json") };
if(!file.exists() || !file.open(QIODevice::ReadOnly)) {
qCDebug(E2EE) << "No sessions cache exists.";
return;
@@ -80,7 +80,7 @@ public:
}
}
void saveSessions() {
- QFile outFile { static_cast<Connection *>(q->parent())->stateCacheDir().filePath("olmsessions.json") };
+ QFile outFile { static_cast<Connection *>(q->parent())->e2eeDataDir() + QStringLiteral("/olmsessions.json") };
if (!outFile.open(QFile::WriteOnly)) {
qCWarning(E2EE) << "Error opening" << outFile.fileName() << ":"
<< outFile.errorString();
diff --git a/lib/room.cpp b/lib/room.cpp
index 94f0c9eb..963b9f88 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -372,7 +372,7 @@ public:
std::map<QPair<QString, QString>, std::unique_ptr<QOlmInboundGroupSession>> groupSessions;
void loadMegOlmSessions() {
- QFile file { connection->stateCacheDir().filePath(QStringLiteral("megolm/%1.json").arg(id)) };
+ QFile file { connection->e2eeDataDir() + QStringLiteral("/%1.json").arg(id) };
if(!file.exists() || !file.open(QIODevice::ReadOnly)) {
qCDebug(E2EE) << "No megolm sessions cache exists.";
return;
@@ -403,8 +403,7 @@ public:
}
}
void saveMegOlmSessions() {
- connection->stateCacheDir().mkdir("megolm");
- QFile outFile { connection->stateCacheDir().filePath(QStringLiteral("megolm/%1.json").arg(id))};
+ QFile outFile { connection->e2eeDataDir() + QStringLiteral("/%1.json").arg(id)};
if (!outFile.open(QFile::WriteOnly)) {
qCWarning(E2EE) << "Error opening" << outFile.fileName() << ":"
<< outFile.errorString();