Ensure blacklisted e2ee files get deleted
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 20 Dec 2022 19:16:06 +0000 (20:16 +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 60750e4d1f05efb1f3ab4d0fab5ffed00aaca246..5a71c6a7c8906ee3417260bbefac589ce9dd41a0 100644 (file)
@@ -1387,6 +1387,32 @@ void Folder::removeLocalE2eFiles()
         slotTerminateSync();
     }
 
+    for (const auto &e2eFilePath : qAsConst(e2eFoldersToBlacklist)) {
+         if (!_journal.deleteFileRecord(e2eFilePath, true)) {
+             qCWarning(lcFolder) << "Failed to delete file record from local DB" << e2eFilePath
+                                 << "it might have already been deleted.";
+             continue;
+         }
+
+         qCDebug(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:" << fullPath;
+             }
+         } else {
+             qCWarning(lcFolder) << "Unable to delete:" << fullPath << "as it does not exist!";
+         }
+     }
+
     for (const auto &path : qAsConst(e2eFoldersToBlacklist)) {
         _journal.schedulePathForRemoteDiscovery(path);
         schedulePathForLocalDiscovery(path);