From: Claudio Cambra Date: Fri, 11 Nov 2022 17:32:12 +0000 (+0100) Subject: Delete E2EE files/folders for accounts that have had E2EE disabled X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~11^2~30^2~18 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=b57b35e7a454c3db8670befbf63a7234af1d2f8c;p=nextcloud-desktop.git Delete E2EE files/folders for accounts that have had E2EE disabled Signed-off-by: Claudio Cambra --- diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index b51cc1188..02a218e05 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -1614,6 +1614,11 @@ void AccountSettings::resetE2eEncryption() _ui->encryptionMessage->setIcon({}); initializeE2eEncryption(); checkClientSideEncryptionState(); + + const auto account = _accountState->account(); + if (account->e2e()->_mnemonic.isEmpty()) { + FolderMan::instance()->removeE2eFiles(account); + } } void AccountSettings::removeActionFromEncryptionMessage(const QString &actionId) diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 0ed956f27..4e297847e 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -1332,6 +1332,60 @@ void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction dir, std::functio msgBox->open(); } +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); + } + }); + + if (!couldGetFiles) { + qCWarning(lcFolder) << "Could not fetch E2EE files to delete in this folder:" << path(); + return; + } else if (e2eFiles.isEmpty()) { + qCWarning(lcFolder) << "No E2EE files found at path" << path(); + return; + } + + const auto currentSyncPaused = syncPaused(); + setSyncPaused(true); + + qCDebug(lcFolder) << "About to remove: " << e2eFiles; + + 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; + } + + 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 file:" << fullPath; + } + } else { + qCWarning(lcFolder) << "Unable to delete:" << fullPath << "as it does not exist!"; + } + } + + setSyncPaused(currentSyncPaused); + _journal.forceRemoteDiscoveryNextSync(); + scheduleThisFolderSoon(); +} + QString Folder::fileFromLocalPath(const QString &localPath) const { return localPath.mid(cleanPath().length() + 1); diff --git a/src/gui/folder.h b/src/gui/folder.h index 8b0e5a8f5..1f9dd79e3 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -370,6 +370,11 @@ public slots: void setSilenceErrorsUntilNextSync(bool silenceErrors); + /** Deletes local copies of E2EE files. + * Intended for clean-up after disabling E2EE for an account. + */ + void removeLocalE2eFiles(); + private slots: void slotSyncStarted(); void slotSyncFinished(bool); diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index b6f9758dc..b8cecf7d2 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -658,6 +658,16 @@ void FolderMan::forceSyncForFolder(Folder *folder) scheduleFolderNext(folder); } +void FolderMan::removeE2eFiles(const AccountPtr &account) const +{ + Q_ASSERT(account->e2e()->_mnemonic.isEmpty()); + for (const auto folder : map()) { + if(folder->accountState()->account()->id() == account->id()) { + folder->removeLocalE2eFiles(); + } + } +} + void FolderMan::slotScheduleAppRestart() { _appRestartRequired = true; diff --git a/src/gui/folderman.h b/src/gui/folderman.h index ee39c259f..a384bd643 100644 --- a/src/gui/folderman.h +++ b/src/gui/folderman.h @@ -271,6 +271,8 @@ public slots: void forceSyncForFolder(OCC::Folder *folder); + void removeE2eFiles(const AccountPtr &account) const; + private slots: void slotFolderSyncPaused(OCC::Folder *, bool paused); void slotFolderCanSyncChanged();