Page MenuHomePhorge

D119.1732369198.diff
No OneTemporary

Size
3 KB
Referenced Files
None
Subscribers
None

D119.1732369198.diff

diff --git a/src/matrix-sdk.cpp b/src/matrix-sdk.cpp
--- a/src/matrix-sdk.cpp
+++ b/src/matrix-sdk.cpp
@@ -56,8 +56,6 @@
zug::identity,
withRandomGenerator(detail::declref<RandomInterface>())));
-static void serializeClientToFile(Client c);
-
struct QtEventLoop
{
QObject *m_obj;
@@ -409,7 +407,10 @@
for (const auto &p : std::filesystem::directory_iterator(allSessionsDir)) {
if (p.is_directory()) {
auto maybeEncodedUserId = p.path().filename().string();
- auto userId = (!maybeEncodedUserId.empty() && maybeEncodedUserId[0] == '@') ? maybeEncodedUserId : decodeBase64(maybeEncodedUserId, Base64Opts::urlSafe);
+ auto userId = decodeBase64(maybeEncodedUserId, Base64Opts::urlSafe);
+ if (userId.empty() || userId[0] != '@') {
+ continue;
+ }
for (const auto &q : std::filesystem::directory_iterator(p.path())) {
auto path = q.path();
auto deviceId = path.filename().string();
@@ -498,15 +499,8 @@
auto userId = parts[0].toStdString();
auto sessionId = parts[1].toStdString();
auto encodedUserId = encodeBase64(userId, Base64Opts::urlSafe);
- qCDebug(kazvLog) << "trying new path";
auto sessionDir = userDataDir / "sessions" / encodedUserId / sessionId;
- if (loadFromSession(sessionDir)) {
- qCDebug(kazvLog) << "new path works";
- return true;
- }
- qCDebug(kazvLog) << "trying legacy path";
- auto legacySessionDir = userDataDir / "sessions" / userId / sessionId;
- return loadFromSession(legacySessionDir);
+ return loadFromSession(sessionDir);
}
qDebug(kazvLog) << "no session found for" << sessionName;
return false;
diff --git a/src/tests/matrix-sdk-sessions-test.cpp b/src/tests/matrix-sdk-sessions-test.cpp
--- a/src/tests/matrix-sdk-sessions-test.cpp
+++ b/src/tests/matrix-sdk-sessions-test.cpp
@@ -7,6 +7,7 @@
#include <kazv-defs.hpp>
#include <memory>
#include <filesystem>
+#include <fstream>
#include <QObject>
#include <QtTest>
#include <crypto/base64.hpp>
@@ -41,6 +42,7 @@
void cleanup();
void testListSessions();
+ void testListLegacySessions();
void testLoadSession();
};
@@ -90,6 +92,29 @@
QCOMPARE(sessionSet, expected);
}
+void MatrixSdkSessionsTest::testListLegacySessions()
+{
+// This test cannot be run on Windows, because the file name
+// there cannot contain ':'.
+#if KAZV_IS_WINDOWS
+ QSKIP("Skipping because there are no legacy sessions on Windows");
+#endif
+
+ createSession("@mew:example.com", "device1");
+ auto legacySession = StdPath(m_userDataDir) / "sessions" / "@mew3:example.com" / "device4";
+ {
+ std::ofstream s{legacySession / "store"};
+ s << "";
+ }
+ auto sdk = makeMatrixSdk();
+
+ QStringList expected{
+ QStringLiteral("@mew:example.com/device1"),
+ };
+
+ QCOMPARE(sdk->allSessions(), expected);
+}
+
void MatrixSdkSessionsTest::testLoadSession()
{
createSession("@mew:example.com", "device1");

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 23, 5:39 AM (14 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39224
Default Alt Text
D119.1732369198.diff (3 KB)

Event Timeline