From: Kevin Ottens Date: Wed, 17 Jun 2020 17:18:04 +0000 (+0200) Subject: Make PropagateUploadEncrypted reusable in a directory context X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~222^2^2~130^2~9 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=319e441653d0b4bfe08b68f3c16c549f6760c493;p=nextcloud-desktop.git Make PropagateUploadEncrypted reusable in a directory context It was assuming we'd encrypt only files but directory names also need to be encrypted. We just skip the writing to temp file part in that case. Signed-off-by: Kevin Ottens --- diff --git a/src/libsync/propagateuploadencrypted.cpp b/src/libsync/propagateuploadencrypted.cpp index d630d425b..2d496c4fe 100644 --- a/src/libsync/propagateuploadencrypted.cpp +++ b/src/libsync/propagateuploadencrypted.cpp @@ -162,27 +162,30 @@ void PropagateUploadEncrypted::slotFolderEncryptedMetadataReceived(const QJsonDo qCDebug(lcPropagateUploadEncrypted) << "Creating the encrypted file."; - QFile input(info.absoluteFilePath()); - QFile output(QDir::tempPath() + QDir::separator() + encryptedFile.encryptedFilename); - - QByteArray tag; - bool encryptionResult = EncryptionHelper::fileEncryption( - encryptedFile.encryptionKey, - encryptedFile.initializationVector, - &input, &output, tag); + if (info.isDir()) { + _completeFileName = encryptedFile.encryptedFilename; + } else { + QFile input(info.absoluteFilePath()); + QFile output(QDir::tempPath() + QDir::separator() + encryptedFile.encryptedFilename); + + QByteArray tag; + bool encryptionResult = EncryptionHelper::fileEncryption( + encryptedFile.encryptionKey, + encryptedFile.initializationVector, + &input, &output, tag); + + if (!encryptionResult) { + qCDebug(lcPropagateUploadEncrypted()) << "There was an error encrypting the file, aborting upload."; + unlockFolder(); + return; + } - if (!encryptionResult) { - qCDebug(lcPropagateUploadEncrypted()) << "There was an error encrypting the file, aborting upload."; - unlockFolder(); - return; + encryptedFile.authenticationTag = tag; + _completeFileName = output.fileName(); } - _completeFileName = output.fileName(); - qCDebug(lcPropagateUploadEncrypted) << "Creating the metadata for the encrypted file."; - encryptedFile.authenticationTag = tag; - _metadata->addEncryptedFile(encryptedFile); _encryptedFile = encryptedFile;