Use e2ee folder blacklist instead of deleting folders directly
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 19 Dec 2022 17:58:37 +0000 (18:58 +0100)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 24 Jan 2023 16:00:15 +0000 (17:00 +0100)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/folder.cpp

index 8c4e54c6e0a16a5462781971d93fefdd6ae96dee..1137096b818e73ffeb608023b64c29023868ea98 100644 (file)
@@ -1335,51 +1335,28 @@ void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction dir, std::functio
 void Folder::removeLocalE2eFiles()
 {
     qCDebug(lcFolder) << "Removing local E2EE files";
-    QByteArrayList e2eFiles;
-    const auto couldGetFiles = _journal.getFilesBelowPath("", [&e2eFiles](const SyncJournalFileRecord &rec) {
-        if (rec._isE2eEncrypted) {
-            e2eFiles.append(rec._path);
+    QStringList e2eFoldersToBlacklist;
+    const auto couldGetFiles = _journal.getFilesBelowPath("", [&e2eFoldersToBlacklist](const SyncJournalFileRecord &rec) {
+        if (rec.isValid() && rec._isE2eEncrypted && rec.isDirectory()) {
+            e2eFoldersToBlacklist.append(rec._path);
         }
     });
 
     if (!couldGetFiles) {
-        qCWarning(lcFolder) << "Could not fetch E2EE files to delete in this folder:" << path();
+        qCWarning(lcFolder) << "Could not fetch E2EE folders to blacklist in this folder:" << path();
         return;
-    } else if (e2eFiles.isEmpty()) {
-        qCWarning(lcFolder) << "No E2EE files found at path" << path();
+    } else if (e2eFoldersToBlacklist.isEmpty()) {
+        qCWarning(lcFolder) << "No E2EE folders found at path" << path();
         return;
     }
 
     const auto currentSyncPaused = syncPaused();
     setSyncPaused(true);
 
-    qCInfo(lcFolder) << "About to remove: " << e2eFiles;
+    qCInfo(lcFolder) << "About to blacklist: " << e2eFoldersToBlacklist;
 
-    for (const auto &e2eFilePath : qAsConst(e2eFiles)) {
-        if (!_journal.deleteFileRecord(e2eFilePath, true)) {
-            qCWarning(lcFolder) << "Failed to delete file record from local DB" << e2eFilePath
-                                << "it might have already been deleted.";
-            continue;
-        }
-
-        qCInfo(lcFolder) << "Removing local copy of" << e2eFilePath;
-
-        const auto fullPath = QString(path() + e2eFilePath);
-        const QFileInfo pathInfo(fullPath);
-
-        if (pathInfo.isDir() && pathInfo.exists()) {
-            QDir dir(fullPath);
-            if (!dir.removeRecursively()) {
-                qCWarning(lcFolder) << "Unable to remove directory and contents at:" << fullPath;
-            }
-        } else if (pathInfo.exists()) {
-            if (!QFile::remove(fullPath)) {
-                qCWarning(lcFolder) << "Unable to delete file:" << fullPath;
-            }
-        } else {
-            qCWarning(lcFolder) << "Unable to delete:" << fullPath << "as it does not exist!";
-        }
-    }
+    // Will get deleted from blacklist if encryption is set up again later
+    _journal.setSelectiveSyncList(SyncJournalDb::SelectiveSyncE2eFoldersToRemoveFromBlacklist, e2eFoldersToBlacklist);
 
     setSyncPaused(currentSyncPaused);
     _journal.forceRemoteDiscoveryNextSync();