diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index f56fdcd3d..679c5620a 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -381,10 +381,7 @@ void PropagateDownloadFile::start() startAfterIsEncryptedIsChecked(); } else { _downloadEncryptedHelper = new PropagateDownloadEncrypted(propagator(), parentPath, _item, this); - connect(_downloadEncryptedHelper, &PropagateDownloadEncrypted::folderStatusNotEncrypted, [this] { - startAfterIsEncryptedIsChecked(); - }); - connect(_downloadEncryptedHelper, &PropagateDownloadEncrypted::folderStatusEncrypted, [this] { + connect(_downloadEncryptedHelper, &PropagateDownloadEncrypted::fileMetadataFound, [this] { _isEncrypted = true; startAfterIsEncryptedIsChecked(); }); diff --git a/src/libsync/propagatedownloadencrypted.cpp b/src/libsync/propagatedownloadencrypted.cpp index 6cbdc8402..8975faff7 100644 --- a/src/libsync/propagatedownloadencrypted.cpp +++ b/src/libsync/propagatedownloadencrypted.cpp @@ -15,11 +15,7 @@ PropagateDownloadEncrypted::PropagateDownloadEncrypted(OwncloudPropagator *propa { } -void PropagateDownloadEncrypted::start() { - checkFolderEncryptedStatus(); -} - -void PropagateDownloadEncrypted::checkFolderEncryptedStatus() +void PropagateDownloadEncrypted::start() { const auto rootPath = [=]() { const auto result = _propagator->remotePath(); @@ -33,37 +29,14 @@ void PropagateDownloadEncrypted::checkFolderEncryptedStatus() const auto remotePath = QString(rootPath + remoteFilename); const auto remoteParentPath = remotePath.left(remotePath.lastIndexOf('/')); - auto getEncryptedStatus = new GetFolderEncryptStatusJob(_propagator->account(), remoteParentPath, this); - connect(getEncryptedStatus, &GetFolderEncryptStatusJob::encryptStatusFolderReceived, - this, &PropagateDownloadEncrypted::folderStatusReceived); - - connect(getEncryptedStatus, &GetFolderEncryptStatusJob::encryptStatusError, - this, &PropagateDownloadEncrypted::folderStatusError); - - getEncryptedStatus->start(); -} - -void PropagateDownloadEncrypted::folderStatusError(int statusCode) -{ - qCDebug(lcPropagateDownloadEncrypted) << "Failed to get encrypted status of folder" << statusCode; -} - -void PropagateDownloadEncrypted::folderStatusReceived(const QString &folder, bool isEncrypted) -{ - qCDebug(lcPropagateDownloadEncrypted) << "Get Folder is Encrypted Received" << folder << isEncrypted; - if (!isEncrypted) { - emit folderStatusNotEncrypted(); - return; - } - - // Is encrypted Now we need the folder-id - auto job = new LsColJob(_propagator->account(), folder, this); - job->setProperties({"resourcetype", "http://owncloud.org/ns:fileid"}); - connect(job, &LsColJob::directoryListingSubfolders, - this, &PropagateDownloadEncrypted::checkFolderId); - connect(job, &LsColJob::finishedWithError, - this, &PropagateDownloadEncrypted::folderIdError); - job->start(); + // Is encrypted Now we need the folder-id + auto job = new LsColJob(_propagator->account(), remoteParentPath, this); + job->setProperties({"resourcetype", "http://owncloud.org/ns:fileid"}); + connect(job, &LsColJob::directoryListingSubfolders, + this, &PropagateDownloadEncrypted::checkFolderId); + connect(job, &LsColJob::finishedWithError, + this, &PropagateDownloadEncrypted::folderIdError); + job->start(); } void PropagateDownloadEncrypted::folderIdError() @@ -101,7 +74,7 @@ void PropagateDownloadEncrypted::checkFolderEncryptedMetadata(const QJsonDocumen _encryptedInfo = file; qCDebug(lcPropagateDownloadEncrypted) << "Found matching encrypted metadata for file, starting download"; - emit folderStatusEncrypted(); + emit fileMetadataFound(); return; } } diff --git a/src/libsync/propagatedownloadencrypted.h b/src/libsync/propagatedownloadencrypted.h index 2d769c746..4df0446df 100644 --- a/src/libsync/propagatedownloadencrypted.h +++ b/src/libsync/propagatedownloadencrypted.h @@ -17,20 +17,16 @@ class PropagateDownloadEncrypted : public QObject { public: PropagateDownloadEncrypted(OwncloudPropagator *propagator, const QString &localParentPath, SyncFileItemPtr item, QObject *parent = nullptr); void start(); - void checkFolderId(const QStringList &list); bool decryptFile(QFile& tmpFile); QString errorString() const; public slots: - void checkFolderEncryptedStatus(); - + void checkFolderId(const QStringList &list); void checkFolderEncryptedMetadata(const QJsonDocument &json); - void folderStatusReceived(const QString &folder, bool isEncrypted); - void folderStatusError(int httpErrorCode); void folderIdError(); + signals: - void folderStatusEncrypted(); - void folderStatusNotEncrypted(); + void fileMetadataFound(); void failed(); void decryptionFinished(); diff --git a/src/libsync/propagateremotemkdir.cpp b/src/libsync/propagateremotemkdir.cpp index 2f67b9af3..4d1703054 100644 --- a/src/libsync/propagateremotemkdir.cpp +++ b/src/libsync/propagateremotemkdir.cpp @@ -183,8 +183,6 @@ void PropagateRemoteMkdir::slotMkdir() // We should be encrypted as well since our parent is const auto remoteParentPath = parentRec._e2eMangledName.isEmpty() ? parentPath : parentRec._e2eMangledName; _uploadEncryptedHelper = new PropagateUploadEncrypted(propagator(), remoteParentPath, _item, this); - connect(_uploadEncryptedHelper, &PropagateUploadEncrypted::folderNotEncrypted, - this, &PropagateRemoteMkdir::slotStartMkcolJob); connect(_uploadEncryptedHelper, &PropagateUploadEncrypted::finalized, this, &PropagateRemoteMkdir::slotStartEncryptedMkcolJob); connect(_uploadEncryptedHelper, &PropagateUploadEncrypted::error, diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp index 6c8af7f1f..d2182df81 100644 --- a/src/libsync/propagateupload.cpp +++ b/src/libsync/propagateupload.cpp @@ -249,8 +249,6 @@ void PropagateUploadFileCommon::start() const auto remoteParentPath = parentRec._e2eMangledName.isEmpty() ? parentPath : parentRec._e2eMangledName; _uploadEncryptedHelper = new PropagateUploadEncrypted(propagator(), remoteParentPath, _item, this); - connect(_uploadEncryptedHelper, &PropagateUploadEncrypted::folderNotEncrypted, - this, &PropagateUploadFileCommon::setupUnencryptedFile); connect(_uploadEncryptedHelper, &PropagateUploadEncrypted::finalized, this, &PropagateUploadFileCommon::setupEncryptedFile); connect(_uploadEncryptedHelper, &PropagateUploadEncrypted::error, diff --git a/src/libsync/propagateuploadencrypted.cpp b/src/libsync/propagateuploadencrypted.cpp index 2bce8b5ad..d02e7bc37 100644 --- a/src/libsync/propagateuploadencrypted.cpp +++ b/src/libsync/propagateuploadencrypted.cpp @@ -44,48 +44,24 @@ void PropagateUploadEncrypted::start() }(); - /* If the file is in a encrypted-enabled nextcloud instance, we need to - * do the long road: Fetch the folder status of the encrypted bit, - * if it's encrypted, find the ID of the folder. - * lock the folder using it's id. - * download the metadata - * update the metadata - * upload the file - * upload the metadata - * unlock the folder. - * - * If the folder is unencrypted we just follow the old way. - */ - qCDebug(lcPropagateUploadEncrypted) << "Starting to send an encrypted file!"; - auto getEncryptedStatus = new GetFolderEncryptStatusJob(_propagator->account(), absoluteRemoteParentPath, this); - - connect(getEncryptedStatus, &GetFolderEncryptStatusJob::encryptStatusFolderReceived, - this, &PropagateUploadEncrypted::slotFolderEncryptedStatusFetched); - connect(getEncryptedStatus, &GetFolderEncryptStatusJob::encryptStatusError, - this, &PropagateUploadEncrypted::slotFolderEncryptedStatusError); - getEncryptedStatus->start(); + /* If the file is in a encrypted folder, which we know, we wouldn't be here otherwise, + * we need to do the long road: + * find the ID of the folder. + * lock the folder using it's id. + * download the metadata + * update the metadata + * upload the file + * upload the metadata + * unlock the folder. + */ + qCDebug(lcPropagateUploadEncrypted) << "Folder is encrypted, let's get the Id from it."; + auto job = new LsColJob(_propagator->account(), absoluteRemoteParentPath, this); + job->setProperties({"resourcetype", "http://owncloud.org/ns:fileid"}); + connect(job, &LsColJob::directoryListingSubfolders, this, &PropagateUploadEncrypted::slotFolderEncryptedIdReceived); + connect(job, &LsColJob::finishedWithError, this, &PropagateUploadEncrypted::slotFolderEncryptedIdError); + job->start(); } -void PropagateUploadEncrypted::slotFolderEncryptedStatusFetched(const QString &folder, bool isEncrypted) -{ - qCDebug(lcPropagateUploadEncrypted) << "Encrypted Status Fetched" << folder << isEncrypted; - - /* We are inside an encrypted folder, we need to find it's Id. */ - if (isEncrypted) { - qCDebug(lcPropagateUploadEncrypted) << "Folder is encrypted, let's get the Id from it."; - auto job = new LsColJob(_propagator->account(), folder, this); - job->setProperties({"resourcetype", "http://owncloud.org/ns:fileid"}); - connect(job, &LsColJob::directoryListingSubfolders, this, &PropagateUploadEncrypted::slotFolderEncryptedIdReceived); - connect(job, &LsColJob::finishedWithError, this, &PropagateUploadEncrypted::slotFolderEncryptedIdError); - job->start(); - } else { - qCDebug(lcPropagateUploadEncrypted) << "Folder is not encrypted, getting back to default."; - emit folderNotEncrypted(); - } -} - - - /* We try to lock a folder, if it's locked we try again in one second. * if it's still locked we try again in one second. looping untill one minute. * -> fail. @@ -286,11 +262,6 @@ void PropagateUploadEncrypted::slotFolderEncryptedIdError(QNetworkReply *r) qCDebug(lcPropagateUploadEncrypted) << "Error retrieving the Id of the encrypted folder."; } -void PropagateUploadEncrypted::slotFolderEncryptedStatusError(int error) -{ - qCDebug(lcPropagateUploadEncrypted) << "Failed to retrieve the status of the folders." << error; -} - void PropagateUploadEncrypted::unlockFolder() { qDebug() << "Calling Unlock"; diff --git a/src/libsync/propagateuploadencrypted.h b/src/libsync/propagateuploadencrypted.h index 33ddbb597..e281a17b1 100644 --- a/src/libsync/propagateuploadencrypted.h +++ b/src/libsync/propagateuploadencrypted.h @@ -42,8 +42,6 @@ public: QByteArray _folderId; private slots: - void slotFolderEncryptedStatusFetched(const QString &folder, bool isEncrypted); - void slotFolderEncryptedStatusError(int error); void slotFolderEncryptedIdReceived(const QStringList &list); void slotFolderEncryptedIdError(QNetworkReply *r); void slotFolderLockedSuccessfully(const QByteArray& fileId, const QByteArray& token); @@ -59,9 +57,6 @@ signals: void finalized(const QString& path, const QString& filename, quint64 size); void error(); - // Emited if the file is not in a encrypted folder. - void folderNotEncrypted(); - private: OwncloudPropagator *_propagator; QString _remoteParentPath;