From 734c1d8dbad48e87a68547d12ad5a6fa525c8a8c Mon Sep 17 00:00:00 2001 From: alex-z Date: Fri, 19 Jan 2024 12:14:40 +0100 Subject: [PATCH] Refactoring and review comments fixing. III. Signed-off-by: alex-z --- src/libsync/discovery.cpp | 4 ---- src/libsync/discoveryphase.cpp | 22 +++++++++------------- src/libsync/discoveryphase.h | 4 ---- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp index eae67e393b547..ebb01f6ee231a 100644 --- a/src/libsync/discovery.cpp +++ b/src/libsync/discovery.cpp @@ -1980,10 +1980,6 @@ DiscoverySingleDirectoryJob *ProcessDirectoryJob::startAsyncServerQuery() connect(serverJob, &DiscoverySingleDirectoryJob::finished, this, [this, serverJob](const auto &results) { if (_dirItem) { if (_dirItem->isEncrypted()) { - if (_dirItem->_encryptedFileName.isEmpty()) { - _discoveryData->_topLevelE2eeFoldersMetadata[_dirItem->_file + QLatin1Char('/')] = serverJob->e2eeFolderMetadata(); - } - _dirItem->_isFileDropDetected = serverJob->isFileDropDetected(); SyncJournalFileRecord record; diff --git a/src/libsync/discoveryphase.cpp b/src/libsync/discoveryphase.cpp index 1a6f58ef09244..4e6478f6358e1 100644 --- a/src/libsync/discoveryphase.cpp +++ b/src/libsync/discoveryphase.cpp @@ -435,11 +435,6 @@ bool DiscoverySingleDirectoryJob::isFileDropDetected() const return _isFileDropDetected; } -QSharedPointer DiscoverySingleDirectoryJob::e2eeFolderMetadata() const -{ - return _e2EeFolderMetadata; -} - bool DiscoverySingleDirectoryJob::encryptedMetadataNeedUpdate() const { return _encryptedMetadataNeedUpdate; @@ -691,22 +686,23 @@ void DiscoverySingleDirectoryJob::metadataReceived(const QJsonDocument &json, in } } - _e2EeFolderMetadata.reset(new FolderMetadata(_account, + const auto e2EeFolderMetadata = new FolderMetadata(_account, statusCode == 404 ? QByteArray{} : json.toJson(QJsonDocument::Compact), RootEncryptedFolderInfo(topLevelFolderPath), - job->signature())); - connect(_e2EeFolderMetadata.data(), &FolderMetadata::setupComplete, this, [this] { - if (!_e2EeFolderMetadata->isValid()) { + job->signature()); + connect(e2EeFolderMetadata, &FolderMetadata::setupComplete, this, [this, e2EeFolderMetadata] { + e2EeFolderMetadata->deleteLater(); + if (!e2EeFolderMetadata->isValid()) { emit finished(HttpError{0, tr("Encrypted metadata setup error!")}); deleteLater(); return; } - _isFileDropDetected = _e2EeFolderMetadata->isFileDropPresent(); - _encryptedMetadataNeedUpdate = _e2EeFolderMetadata->encryptedMetadataNeedUpdate(); + _isFileDropDetected = e2EeFolderMetadata->isFileDropPresent(); + _encryptedMetadataNeedUpdate = e2EeFolderMetadata->encryptedMetadataNeedUpdate(); _encryptionStatusRequired = EncryptionStatusEnums::fromEndToEndEncryptionApiVersion(_account->capabilities().clientSideEncryptionVersion()); - _encryptionStatusCurrent = _e2EeFolderMetadata->existingMetadataEncryptionStatus(); + _encryptionStatusCurrent = e2EeFolderMetadata->existingMetadataEncryptionStatus(); - const auto encryptedFiles = _e2EeFolderMetadata->files(); + const auto encryptedFiles = e2EeFolderMetadata->files(); const auto findEncryptedFile = [=](const QString &name) { const auto it = std::find_if(std::cbegin(encryptedFiles), std::cend(encryptedFiles), [=](const FolderMetadata::EncryptedFile &file) { diff --git a/src/libsync/discoveryphase.h b/src/libsync/discoveryphase.h index 1454aa052a617..8d6d615c3665a 100644 --- a/src/libsync/discoveryphase.h +++ b/src/libsync/discoveryphase.h @@ -152,7 +152,6 @@ class DiscoverySingleDirectoryJob : public QObject void start(); void abort(); [[nodiscard]] bool isFileDropDetected() const; - [[nodiscard]] QSharedPointer e2eeFolderMetadata() const; [[nodiscard]] bool encryptedMetadataNeedUpdate() const; [[nodiscard]] SyncFileItem::EncryptionStatus currentEncryptionStatus() const; [[nodiscard]] SyncFileItem::EncryptionStatus requiredEncryptionStatus() const; @@ -197,8 +196,6 @@ private slots: int64_t _size = 0; QString _error; QPointer _lsColJob; - - QSharedPointer _e2EeFolderMetadata; // store top level E2EE folder paths as they are used later when discovering nested folders QSet _topLevelE2eeFolderPaths; @@ -337,7 +334,6 @@ class DiscoveryPhase : public QObject bool _noCaseConflictRecordsInDb = false; QSet _topLevelE2eeFolderPaths; - QMap> _topLevelE2eeFoldersMetadata; signals: void fatalError(const QString &errorString, const OCC::ErrorCategory errorCategory);