Update the metadata table with encryption info before discovery
authorKevin Ottens <kevin.ottens@nextcloud.com>
Thu, 2 Jul 2020 15:24:58 +0000 (17:24 +0200)
committerKevin Ottens (Rebase PR Action) <er-vin@users.noreply.github.com>
Mon, 6 Jul 2020 05:27:14 +0000 (05:27 +0000)
When the ClientSideEncryption object is fed, also serialize the
encryption info of the folders inside the metadata table.

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
src/libsync/syncengine.cpp
src/libsync/syncengine.h

index 1875100ef467bf14c80c55ffc5e88dc4c4a4dc56..cd20bf4bede491362fe588f84f352ec302faa607 100644 (file)
@@ -869,10 +869,53 @@ void SyncEngine::startSync()
     }
 }
 
-void SyncEngine::onFolderEncryptedStatusFetchDone()
+void SyncEngine::onFolderEncryptedStatusFetchDone(const QHash<QString, bool> &values)
 {
     disconnect(_account->e2e(), &ClientSideEncryption::folderEncryptedStatusFetchDone,
                this, &SyncEngine::onFolderEncryptedStatusFetchDone);
+
+    Q_ASSERT(_remotePath.startsWith('/'));
+    const auto rootPath = [=]() {
+        const auto result = _remotePath;
+        if (result.startsWith('/')) {
+            return result.mid(1);
+        } else {
+            return result;
+        }
+    }();
+
+    std::for_each(values.constKeyValueBegin(), values.constKeyValueEnd(), [=](const std::pair<QString, bool> &pair) {
+        const auto key = pair.first;
+        const auto value = pair.second;
+
+        if (!key.startsWith(rootPath)) {
+            return;
+        }
+
+        Q_ASSERT(key.endsWith('/'));
+        const auto path = key.mid(rootPath.length()).chopped(1);
+
+        if (path.isEmpty()) {
+            // We don't store metadata about the root
+            return;
+        }
+
+        SyncJournalFileRecord rec;
+        _journal->getFileRecordByE2eMangledName(path, &rec);
+
+        if (!rec.isValid()) {
+            _journal->getFileRecord(path, &rec);
+        }
+
+        if (!rec.isValid()) {
+            // We don't know that folder yet anyway...
+            return;
+        }
+
+        rec._isE2eEncrypted = value;
+        _journal->setFileRecord(rec);
+    });
+
     slotStartDiscovery();
 }
 
index 7f21eee3e948e7565c0d745ef3d5ebdbc5d5264c..d186bc6271d7da123be3ebe943d112cc9ddae823 100644 (file)
@@ -168,7 +168,7 @@ signals:
     void seenLockedFile(const QString &fileName);
 
 private slots:
-    void onFolderEncryptedStatusFetchDone();
+    void onFolderEncryptedStatusFetchDone(const QHash<QString, bool> &values);
     void slotStartDiscovery();
 
     void slotFolderDiscovered(bool local, const QString &folder);