From 6f35cbff6bb5dad94efe8ef30524b1d013f29189 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Mon, 4 Dec 2017 22:27:13 +0100 Subject: [PATCH] [CSE] Fetch the Folder information for encryption status --- src/libsync/clientsideencryption.h | 3 -- src/libsync/propagateupload.cpp | 60 +++++++++++++++++++++++------- src/libsync/propagateupload.h | 6 ++- 3 files changed, 51 insertions(+), 18 deletions(-) diff --git a/src/libsync/clientsideencryption.h b/src/libsync/clientsideencryption.h index 580818703..3873ba414 100644 --- a/src/libsync/clientsideencryption.h +++ b/src/libsync/clientsideencryption.h @@ -43,9 +43,6 @@ public: void setTokenForFolder(const QByteArray& folder, const QByteArray& token); QByteArray tokenForFolder(const QByteArray& folder) const; - //TODO: Perhaps mode this to FolderStatusModel - // (as it makes sense, but it increase the chance - // of conflicts). void fetchFolderEncryptedStatus(); // to be used together with FolderStatusModel::FolderInfo::_path. diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp index 26d34cebf..ab5640519 100644 --- a/src/libsync/propagateupload.cpp +++ b/src/libsync/propagateupload.cpp @@ -26,6 +26,7 @@ #include "syncengine.h" #include "propagateremotedelete.h" #include "common/asserts.h" +#include "networkjobs.h" #include #include @@ -177,29 +178,60 @@ void PropagateUploadFileCommon::start() * this by no means is a finished job, but a first step. */ if (propagator()->account()->capabilities().clientSideEncryptionAvaliable()) { - qDebug() << "Uploading to Remote Folder: " << propagator()->_remoteFolder; - qDebug() << "Uploading from Local Dir" << propagator()->_localDir; - qDebug() << "Local File" << _item->_file; - qDebug() << QDir::cleanPath(propagator()->account()->url().path() + QLatin1Char('/') - + propagator()->account()->davPath() + propagator()->_remoteFolder + _item->_file); - - //TODO: Those shall die. + /* 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. + */ + auto getEncryptedStatus = new GetFolderEncryptStatus(propagator()->account()); + connect(getEncryptedStatus, &GetFolderEncryptStatus::encryptStatusReceived, + this, &PropagateUploadFileCommon::slotFolderEncryptedStatusFetched); + connect(getEncryptedStatus, &GetFolderEncryptStatus::encryptStatusError, + this, &PropagateUploadFileCommon::slotFolderEncryptedStatusError); + getEncryptedStatus->start(); + } else { _fileToUpload._file = _item->_file; _fileToUpload._size = _item->_size; _fileToUpload._path = propagator()->getFilePath(_fileToUpload._file); - } else { - _fileToUpload._file = _item->_file; - _fileToUpload._size = _item->_size; - _fileToUpload._path = propagator()->getFilePath(_fileToUpload._file); - startUploadRawFile(); + startUploadFile(); } } -void PropageteUploadFileCommon::startUploadEncryptedFile() + +void PropagateUploadFileCommon::slotFolderEncryptedStatusFetched(const QMap& result) +{ + qDebug() << "####################################"; + qDebug() << "Encrypted Status Result by folder:"; + for(const auto& path : result.keys()) { + qDebug() << result[path] << path; + } + qDebug() << "Uploading to Remote Folder: " << propagator()->_remoteFolder; + qDebug() << "Uploading from Local Dir" << propagator()->_localDir; + qDebug() << "Local File" << _item->_file; + qDebug() << QDir::cleanPath(propagator()->account()->url().path() + QLatin1Char('/') + + propagator()->account()->davPath() + propagator()->_remoteFolder + _item->_file); + qDebug() << "###################################"; + qDebug() << "Retrieved correctly the encrypted status of the folders." << result; +} + +void PropagateUploadFileCommon::slotFolderEncryptedStatusError(int error) +{ + qDebug() << "Failed to retrieve the status of the folders." << error; +} + + +void PropagateUploadFileCommon::startUploadEncryptedFile() { } -void PropagateUploadFileCommon::startUploadRawFile() { +void PropagateUploadFileCommon::startUploadFile() { if (propagator()->_abortRequested.fetchAndAddRelaxed(0)) { return; } diff --git a/src/libsync/propagateupload.h b/src/libsync/propagateupload.h index b0e576a24..10f459381 100644 --- a/src/libsync/propagateupload.h +++ b/src/libsync/propagateupload.h @@ -253,7 +253,7 @@ public: /* start should setup the file, path and size that will be send to the server */ void start() Q_DECL_OVERRIDE; void startUploadEncryptedFile(); - void startUploadRawFile(); + void startUploadFile(); bool isLikelyFinishedQuickly() Q_DECL_OVERRIDE { return _item->_size < propagator()->smallFileSize(); } private slots: @@ -278,6 +278,10 @@ private slots: void slotReplyAbortFinished(); void slotPollFinished(); + // Encryption Stuff + void slotFolderEncryptedStatusFetched(const QMap& result); + void slotFolderEncryptedStatusError(int error); + protected: /** * Prepares the abort e.g. connects proper signals and slots