Migrate journal dbs files back to the sync folder
authorKevin Ottens <kevin.ottens@nextcloud.com>
Thu, 5 Nov 2020 16:18:13 +0000 (17:18 +0100)
committerKevin Ottens (Rebase PR Action) <er-vin@users.noreply.github.com>
Tue, 10 Nov 2020 17:46:43 +0000 (17:46 +0000)
In case of past collisions during the 3.0 times... well one will resync
from scratch unfortunately. But if that happened there are likely other
problems which occurred.

Also this might fix some of the bugs with people loosing settings from
the database. Indeed the -wal and -shm concatenations were wrong. Using
append was in fact changing the folderDefinition member which (I guess)
would potentially lead to funny ".db-wal-shm-wal-shm" names.

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
src/gui/folderman.cpp

index 422657f8297d6608d2856f9a88faa899c4674681..818337687e5b78c75e50bcb92c5850862b85776e 100644 (file)
@@ -207,11 +207,11 @@ void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account,
                 folderDefinition.journalPath = defaultJournalPath;
             }
 
-            // Migration #2: journalPath now in DataAppDir, not root of local tree (cross-platform persistent user roaming files)
-            if (folderDefinition.journalPath.at(0) == QChar('.')) {
-                QFile oldJournal(folderDefinition.localPath + "/" + folderDefinition.journalPath);
-                QFile oldJournalShm(folderDefinition.localPath + "/" + folderDefinition.journalPath.append("-shm"));
-                QFile oldJournalWal(folderDefinition.localPath + "/" + folderDefinition.journalPath.append("-wal"));
+            // Migration #2: journalPath might be absolute (in DataAppDir most likely) move it back to the root of local tree
+            if (folderDefinition.journalPath.at(0) != QChar('.')) {
+                QFile oldJournal(folderDefinition.journalPath);
+                QFile oldJournalShm(folderDefinition.journalPath + QStringLiteral("-shm"));
+                QFile oldJournalWal(folderDefinition.journalPath + QStringLiteral("-wal"));
 
                 folderDefinition.journalPath = defaultJournalPath;
 
@@ -221,17 +221,17 @@ void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account,
                 auto journalFileMoveSuccess = true;
                 // Due to db logic can't be sure which of these file exist.
                 if (oldJournal.exists()) {
-                    journalFileMoveSuccess &= oldJournal.rename(folderDefinition.journalPath);
+                    journalFileMoveSuccess &= oldJournal.rename(folderDefinition.localPath + "/" + folderDefinition.journalPath);
                 }
                 if (oldJournalShm.exists()) {
-                    journalFileMoveSuccess &= oldJournalShm.rename(folderDefinition.journalPath.append("-shm"));
+                    journalFileMoveSuccess &= oldJournalShm.rename(folderDefinition.localPath + "/" + folderDefinition.journalPath + QStringLiteral("-shm"));
                 }
                 if (oldJournalWal.exists()) {
-                    journalFileMoveSuccess &= oldJournalWal.rename(folderDefinition.journalPath.append("-wal"));
+                    journalFileMoveSuccess &= oldJournalWal.rename(folderDefinition.localPath + "/" + folderDefinition.journalPath + QStringLiteral("-wal"));
                 }
 
                 if (!journalFileMoveSuccess) {
-                    qCWarning(lcFolderMan) << "Wasn't able to move pre-2.7 syncjournal database files to new location. One-time loss off sync settings possible.";
+                    qCWarning(lcFolderMan) << "Wasn't able to move 3.0 syncjournal database files to new location. One-time loss off sync settings possible.";
                 } else {
                     qCInfo(lcFolderMan) << "Successfully migrated syncjournal database.";
                 }