Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHannah von Reth <hannah.vonreth@owncloud.com>2021-09-17 17:54:08 +0300
committerHannah von Reth <vonreth@kde.org>2021-09-21 10:35:35 +0300
commit4951b52ac6d62cf6b2601e908d397063d47c489d (patch)
tree5c3b6848d55e5f1dc99a058f0b132b20f1d33331
parent37dbdc9cea118b947dacdae34000967aa7a097a5 (diff)
Fix migration on minor url format changes like…
…https://demo.owncloud.org/ to https://demo.owncloud.org This commit also removed the infix from the cmd client, as it is to unreliable.
-rw-r--r--changelog/unreleased/90193
-rw-r--r--src/cmd/cmd.cpp2
-rw-r--r--src/common/syncjournaldb.cpp7
-rw-r--r--src/common/syncjournaldb.h5
-rw-r--r--src/gui/folderman.cpp15
-rw-r--r--src/gui/folderman.h3
-rw-r--r--test/CMakeLists.txt2
-rw-r--r--test/testfoldermigration.cpp100
-rw-r--r--test/testutils/testutils.cpp8
9 files changed, 126 insertions, 19 deletions
diff --git a/changelog/unreleased/9019 b/changelog/unreleased/9019
index 5f9e2162e..a4058229f 100644
--- a/changelog/unreleased/9019
+++ b/changelog/unreleased/9019
@@ -11,6 +11,9 @@ This configuration is know to lead to dataloss and is no longer supported.
Please consider removing this folder from the account and adding it again.
```
+We also removed the account info infix from the sync db used with the cmd client.
+
https://github.com/owncloud/client/issues/9019
https://github.com/owncloud/client/pull/9028
https://github.com/owncloud/client/pull/9046
+https://github.com/owncloud/client/pull/9054
diff --git a/src/cmd/cmd.cpp b/src/cmd/cmd.cpp
index 3270f49e2..4b15d61b5 100644
--- a/src/cmd/cmd.cpp
+++ b/src/cmd/cmd.cpp
@@ -137,7 +137,7 @@ void sync(const SyncCTX &ctx)
}
}
- const QString dbPath = ctx.options.source_dir + SyncJournalDb::makeDbName(ctx.options.source_dir, ctx.credentialFreeUrl, ctx.folder, ctx.user);
+ const QString dbPath = ctx.options.source_dir + SyncJournalDb::makeDbName(ctx.options.source_dir);
auto db = new SyncJournalDb(dbPath, qApp);
if (!selectiveSyncList.empty()) {
selectiveSyncFixup(db, selectiveSyncList);
diff --git a/src/common/syncjournaldb.cpp b/src/common/syncjournaldb.cpp
index 2dc45c4f8..fcef0f69a 100644
--- a/src/common/syncjournaldb.cpp
+++ b/src/common/syncjournaldb.cpp
@@ -127,13 +127,6 @@ QString SyncJournalDb::makeDbName(const QString &localPath,
return journalPath;
}
-QString SyncJournalDb::makeDbName(const QString &localPath, const QUrl &remoteUrl, const QString &remotePath, const QString &user)
-{
- // legacy name only used by the cmd client
- const QString key = QStringLiteral("%1@%2:%3").arg(user, remoteUrl.toString(), remotePath);
- return makeDbName(localPath, QString::fromUtf8(QCryptographicHash::hash(key.toUtf8(), QCryptographicHash::Md5).left(6).toHex()));
-}
-
bool SyncJournalDb::maybeMigrateDb(const QString &localPath, const QString &absoluteJournalPath)
{
const QString oldDbName = localPath + QLatin1String(".csync_journal.db");
diff --git a/src/common/syncjournaldb.h b/src/common/syncjournaldb.h
index 0f0bb7146..03a222304 100644
--- a/src/common/syncjournaldb.h
+++ b/src/common/syncjournaldb.h
@@ -52,11 +52,6 @@ public:
static QString makeDbName(const QString &localPath,
const QString &infix = QStringLiteral("journal"));
- static QString makeDbName(const QString &localPath,
- const QUrl &remoteUrl,
- const QString &remotePath,
- const QString &user);
-
/// Migrate a csync_journal to the new path, if necessary. Returns false on error
static bool maybeMigrateDb(const QString &localPath, const QString &absoluteJournalPath);
diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp
index 78b186f8f..da54e3eaf 100644
--- a/src/gui/folderman.cpp
+++ b/src/gui/folderman.cpp
@@ -45,6 +45,17 @@ int numberOfSyncJournals(const QString &path)
return QDir(path).entryList({ QStringLiteral(".sync_*.db"), QStringLiteral("._sync_*.db") }, QDir::Hidden | QDir::Files).size();
}
+QString makeLegacyDbName(const OCC::FolderDefinition &def, const OCC::AccountPtr &account)
+{
+ // ensure https://demo.owncloud.org/ matches https://demo.owncloud.org
+ // the empty path was the legacy formating before 2.9
+ auto legacyUrl = account->url();
+ if (legacyUrl.path() == QLatin1String("/")) {
+ legacyUrl.setPath(QString());
+ }
+ const QString key = QStringLiteral("%1@%2:%3").arg(account->credentials()->user(), legacyUrl.toString(), def.targetPath);
+ return OCC::SyncJournalDb::makeDbName(def.localPath, QString::fromUtf8(QCryptographicHash::hash(key.toUtf8(), QCryptographicHash::Md5).left(6).toHex()));
+}
}
namespace OCC {
@@ -289,13 +300,13 @@ void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account,
const auto defaultJournalPath = [&account, folderDefinition] {
// if we would have booth the 2.9.0 file name and the lagacy file
// with the md5 infix we prefer the 2.9.0 version
- const QFileInfo info(folderDefinition.localPath);
+ const QDir info(folderDefinition.localPath);
const QString defaultPath = SyncJournalDb::makeDbName(folderDefinition.localPath);
if (info.exists(defaultPath)) {
return defaultPath;
}
// 2.6
- QString legacyPath = SyncJournalDb::makeDbName(folderDefinition.localPath, account->account()->url(), folderDefinition.targetPath, account->account()->credentials()->user());
+ QString legacyPath = makeLegacyDbName(folderDefinition, account->account());
if (info.exists(legacyPath)) {
return legacyPath;
}
diff --git a/src/gui/folderman.h b/src/gui/folderman.h
index e5c566918..570df8796 100644
--- a/src/gui/folderman.h
+++ b/src/gui/folderman.h
@@ -25,6 +25,8 @@
#include "navigationpanehelper.h"
#include "syncfileitem.h"
+class TestFolderMigration;
+
namespace OCC {
namespace TestUtils {
// prototype for test friend
@@ -387,6 +389,7 @@ private:
explicit FolderMan(QObject *parent = nullptr);
friend class OCC::Application;
friend OCC::FolderMan *OCC::TestUtils::folderMan();
+ friend class ::TestFolderMigration;
};
} // namespace OCC
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 80299ab72..d706c9d63 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -40,6 +40,8 @@ owncloud_add_test(SelectiveSync)
owncloud_add_test(DatabaseError)
owncloud_add_test(LockedFiles)
+owncloud_add_test(FolderMigration)
+
owncloud_add_test(FolderWatcher)
if( UNIX AND NOT APPLE )
diff --git a/test/testfoldermigration.cpp b/test/testfoldermigration.cpp
new file mode 100644
index 000000000..24eb290f8
--- /dev/null
+++ b/test/testfoldermigration.cpp
@@ -0,0 +1,100 @@
+/*
+ * This software is in the public domain, furnished "as is", without technical
+ * support, and with no warranty, express or implied, as to its usefulness for
+ * any purpose.
+ *
+ */
+
+#include <QtTest>
+
+#include "accountmanager.h"
+#include "common/utility.h"
+#include "configfile.h"
+#include "folderman.h"
+
+using namespace OCC;
+
+namespace {
+auto Settings_2_4()
+{
+ return QStringLiteral(R"([Accounts]
+ version=2
+ 0\Folders\1\localPath=
+ 0\Folders\1\journalPath=._sync_2215dfc5505b.db
+ 0\url=https://demo.owncloud.com
+ 0\Folders\1\targetPath=/
+ 0\http_oauth=true
+ 0\serverVersion=10.8.0.4
+ 0\Folders\1\paused=false
+ 0\http_user=admin
+ 0\Folders\1\ignoreHiddenFiles=true
+ 0\authType=http
+ 0\user=admin)");
+}
+
+}
+
+class TestFolderMigration : public QObject
+{
+ Q_OBJECT
+private:
+ auto writeSettings(const QTemporaryDir &tmp, const QString &content)
+ {
+ QFile settingsFile(ConfigFile::configFile());
+ OC_ENFORCE(settingsFile.open(QFile::WriteOnly));
+ settingsFile.write(content.toUtf8());
+ settingsFile.close();
+
+ auto settings = ConfigFile::settingsWithGroup(QStringLiteral("Accounts"));
+ settings->setValue("0/Folders/1/localPath", tmp.path());
+ qDebug() << settings->childGroups() << settings->childKeys();
+
+
+ return settings;
+ }
+private slots:
+ void testFolderMigrationMissingJurnalPath_data()
+ {
+ QTest::addColumn<QStringList>("journalPaths");
+ QTest::addColumn<QString>("url");
+
+ QTest::newRow("2.4") << QStringList { "._sync_2215dfc5505b.db" } << "https://demo.owncloud.com";
+ QTest::newRow("2.4 url") << QStringList { "._sync_2215dfc5505b.db" } << "https://demo.owncloud.com/";
+ QTest::newRow("2.6") << QStringList { ".sync_2215dfc5505b.db" } << "https://demo.owncloud.com";
+ QTest::newRow("2.6 url") << QStringList { ".sync_2215dfc5505b.db" } << "https://demo.owncloud.com/";
+ QTest::newRow("2.6 multi") << QStringList { ".sync_2215dfc5505b.db", "._sync_2215dfc5505b.db" } << "https://demo.owncloud.com";
+ QTest::newRow("2.9") << QStringList { ".sync_journal.db" } << "https://demo.owncloud.com";
+ QTest::newRow("2.9 url") << QStringList { ".sync_journal.db" } << "https://demo.owncloud.com/";
+ QTest::newRow("2.9 multi") << QStringList { ".sync_journal.db", ".sync_2215dfc5505b.db", "._sync_2215dfc5505b.db" } << "https://demo.owncloud.com";
+ }
+
+ void testFolderMigrationMissingJurnalPath()
+ {
+ QFETCH(QStringList, journalPaths);
+ QFETCH(QString, url);
+ QTemporaryDir tmp;
+ const auto settings = writeSettings(tmp, Settings_2_4());
+ settings->setValue("0/url", url);
+ settings->remove("0/Folders/1/journalPath");
+ QVERIFY(!settings->value("0/Folders/1/journalPath").isValid());
+
+ for (const auto &journalPath : journalPaths) {
+ QFile syncDb(tmp.filePath(journalPath));
+ QVERIFY(syncDb.open(QFile::WriteOnly));
+ syncDb.write("foo");
+ syncDb.close();
+ }
+
+ AccountManager::instance()->restore();
+
+ settings->beginGroup("0/Folders");
+ TestUtils::folderMan()->setupFoldersHelper(*settings.get(), AccountManager::instance()->accounts().first(), {}, true, false);
+ settings->endGroup();
+
+ QCOMPARE(journalPaths.first(), settings->value("0/Folders/1/journalPath"));
+ delete TestUtils::folderMan();
+ }
+};
+
+QTEST_MAIN(TestFolderMigration)
+#include "testfoldermigration.moc"
diff --git a/test/testutils/testutils.cpp b/test/testutils/testutils.cpp
index 281323073..0d2c5d43d 100644
--- a/test/testutils/testutils.cpp
+++ b/test/testutils/testutils.cpp
@@ -47,11 +47,11 @@ namespace TestUtils {
FolderMan *folderMan()
{
- static FolderMan *man = [] {
- auto man = new FolderMan;
+ static QPointer<FolderMan> man;
+ if (!man) {
+ man = new FolderMan;
QObject::connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, man, &FolderMan::deleteLater);
- return man;
- }();
+ };
return man;
}