Only add root-most encrypted folder to the blacklist
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 20 Dec 2022 12:26:27 +0000 (13:26 +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 05e2a07a41af3904920936609bdcece8d3aefe32..755f4c219f2175414170974ec3f88a8e150b5168 100644 (file)
@@ -1335,10 +1335,32 @@ void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction dir, std::functio
 void Folder::removeLocalE2eFiles()
 {
     qCDebug(lcFolder) << "Removing local E2EE files";
+
+    const QDir folderRootDir(path());
     QStringList e2eFoldersToBlacklist;
-    const auto couldGetFiles = _journal.getFilesBelowPath("", [&e2eFoldersToBlacklist](const SyncJournalFileRecord &rec) {
+    const auto couldGetFiles = _journal.getFilesBelowPath("", [this, &e2eFoldersToBlacklist, &folderRootDir](const SyncJournalFileRecord &rec) {
+        // We only want to add the root-most encrypted folder to the blacklist
         if (rec.isValid() && rec._isE2eEncrypted && rec.isDirectory()) {
-            e2eFoldersToBlacklist.append(rec._path);
+            QDir pathDir(rec._path);
+            bool parentPathEncrypted = false;
+
+            while (pathDir.cdUp() && pathDir != folderRootDir) {
+                SyncJournalFileRecord rec;
+                const auto currentCanonicalPath = pathDir.canonicalPath();
+                const auto ok = _journal.getFileRecord(currentCanonicalPath, &rec);
+                if (!ok) {
+                    qCWarning(lcFolder) << "Failed to get file record for" << currentCanonicalPath;
+                }
+
+                if (rec._isE2eEncrypted) {
+                    parentPathEncrypted = true;
+                    break;
+                }
+            }
+
+            if (!parentPathEncrypted) {
+                e2eFoldersToBlacklist.append(rec._path);
+            }
         }
     });