Also check on mangled names when cleaning up the journal
authorKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 30 Jun 2020 08:24:40 +0000 (10:24 +0200)
committerKevin Ottens (Rebase PR Action) <er-vin@users.noreply.github.com>
Wed, 1 Jul 2020 16:58:29 +0000 (16:58 +0000)
Otherwise, after a first sync all the mangled entries would be removed
from the journal. On second sync it would be fine because we'd then have
seen the unmangled names because of the local files. Unfortunately
that'd mean reuploading them for nothing or trying to mkdir again on the
server for nothing... with a chance of using differently mangled names
(although I didn't spot it, I can't exclude it never happened).

This also led to weirdly getting stuck during sync when there was more
than one sync point.

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

index ff4e352fe2ae847e4d2633261a7feeaa798e2e39..43b0b045ce803e410c394af87965ed3a7c10950e 100644 (file)
@@ -1133,7 +1133,7 @@ bool SyncJournalDb::postSyncCleanup(const QSet<QString> &filepathsToKeep,
     }
 
     SqlQuery query(_db);
-    query.prepare("SELECT phash, path FROM metadata order by path");
+    query.prepare("SELECT phash, path, e2eMangledName FROM metadata order by path");
 
     if (!query.exec()) {
         return false;
@@ -1142,11 +1142,12 @@ bool SyncJournalDb::postSyncCleanup(const QSet<QString> &filepathsToKeep,
     QByteArrayList superfluousItems;
 
     while (query.next()) {
-        const QString file = query.baValue(1);
-        bool keep = filepathsToKeep.contains(file);
+        const auto file = QString(query.baValue(1));
+        const auto mangledPath = QString(query.baValue(2));
+        bool keep = filepathsToKeep.contains(file) || filepathsToKeep.contains(mangledPath);
         if (!keep) {
             foreach (const QString &prefix, prefixesToKeep) {
-                if (file.startsWith(prefix)) {
+                if (file.startsWith(prefix) || mangledPath.startsWith(prefix)) {
                     keep = true;
                     break;
                 }