Make PropagateUploadEncrypted reusable in a directory context
authorKevin Ottens <kevin.ottens@nextcloud.com>
Wed, 17 Jun 2020 17:18:04 +0000 (19:18 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 30 Jun 2020 09:29:08 +0000 (11:29 +0200)
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 <kevin.ottens@nextcloud.com>
src/libsync/propagateuploadencrypted.cpp

index d630d425beb8c23fdf41bf57a2ee6abd064c9b4a..2d496c4fe604afa5fbea1464f140e86b7fc2f480 100644 (file)
@@ -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;