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();
});
{
}
-void PropagateDownloadEncrypted::start() {
- checkFolderEncryptedStatus();
-}
-
-void PropagateDownloadEncrypted::checkFolderEncryptedStatus()
+void PropagateDownloadEncrypted::start()
{
const auto rootPath = [=]() {
const auto result = _propagator->remotePath();
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()
_encryptedInfo = file;
qCDebug(lcPropagateDownloadEncrypted) << "Found matching encrypted metadata for file, starting download";
- emit folderStatusEncrypted();
+ emit fileMetadataFound();
return;
}
}
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();
// 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,
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,
}();
- /* 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();
-}
-
-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();
- }
+ /* 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();
}
-
-
/* 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.
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";
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);
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;