Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Cambra <claudio.cambra@nextcloud.com>2022-11-11 20:32:12 +0300
committerClaudio Cambra <claudio.cambra@nextcloud.com>2022-11-11 23:34:11 +0300
commit2eac458099d970116f0ceb864fa07a63ece98fc8 (patch)
treee5e519fb4fb23530fc48d7f726aa1e435d3f3450
parent5342134e16a25462e35959315636e858b020d7c2 (diff)
Delete E2EE files/folders for accounts that have had E2EE disabledfeature/disable-e2ee
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
-rw-r--r--src/gui/accountsettings.cpp5
-rw-r--r--src/gui/folder.cpp53
-rw-r--r--src/gui/folder.h5
-rw-r--r--src/gui/folderman.cpp10
-rw-r--r--src/gui/folderman.h2
5 files changed, 75 insertions, 0 deletions
diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp
index b702d1616..795835cbb 100644
--- a/src/gui/accountsettings.cpp
+++ b/src/gui/accountsettings.cpp
@@ -1509,6 +1509,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 9a50716a1..d1300686d 100644
--- a/src/gui/folder.cpp
+++ b/src/gui/folder.cpp
@@ -1303,6 +1303,59 @@ 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);
+ 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 217668311..0f5a69492 100644
--- a/src/gui/folder.h
+++ b/src/gui/folder.h
@@ -368,6 +368,11 @@ public slots:
/** Ensures that the next sync performs a full local discovery. */
void slotNextSyncFullLocalDiscovery();
+ /** 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 b71a9593d..bc5ce0462 100644
--- a/src/gui/folderman.cpp
+++ b/src/gui/folderman.cpp
@@ -615,6 +615,16 @@ void FolderMan::forceSyncForFolder(Folder *folder)
scheduleFolderNext(folder);
}
+void FolderMan::removeE2eFiles(const AccountPtr &account)
+{
+ 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 6409cc8b4..dcbcca672 100644
--- a/src/gui/folderman.h
+++ b/src/gui/folderman.h
@@ -267,6 +267,8 @@ public slots:
void forceSyncForFolder(Folder *folder);
+ void removeE2eFiles(const AccountPtr &account);
+
private slots:
void slotFolderSyncPaused(Folder *, bool paused);
void slotFolderCanSyncChanged();