Deal properly with encrypted item updates accross connections
authorKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 30 Jun 2020 15:20:02 +0000 (17:20 +0200)
committerKevin Ottens (Rebase PR Action) <er-vin@users.noreply.github.com>
Wed, 1 Jul 2020 16:58:29 +0000 (16:58 +0000)
In such cases we get a download for which _file is already the demangled
name and _encryptedFileName has the mangled information. This is
different to what we encountered so far where initially _file was
mangled and _encryptedFileName was empty. Let's deal with that case
properly.

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
src/libsync/propagatedownload.cpp
src/libsync/propagatedownloadencrypted.cpp

index 94f3a99a5c6b9ee5c7b1db615f4c68f4606e06d7..473c5d70b416c374e14d5d7c3ec8c524258161ca 100644 (file)
@@ -351,7 +351,8 @@ void PropagateDownloadFile::start()
             return result;
         }
     }();
-    const auto remotePath = QString(rootPath + _item->_file);
+    const auto remoteFilename = _item->_encryptedFileName.isEmpty() ? _item->_file : _item->_encryptedFileName;
+    const auto remotePath = QString(rootPath + remoteFilename);
     const auto remoteParentPath = remotePath.left(remotePath.lastIndexOf('/'));
 
     const auto account = propagator()->account();
@@ -359,9 +360,8 @@ void PropagateDownloadFile::start()
         !account->e2e()->isFolderEncrypted(remoteParentPath + '/')) {
         startAfterIsEncryptedIsChecked();
     } else {
-        const auto relativeRemotePath = _item->_file;
-        const auto slashPosition = relativeRemotePath.lastIndexOf('/');
-        const auto relativeRemoteParentPath = slashPosition >= 0 ? relativeRemotePath.left(slashPosition) : QString();
+        const auto slashPosition = remoteFilename.lastIndexOf('/');
+        const auto relativeRemoteParentPath = slashPosition >= 0 ? remoteFilename.left(slashPosition) : QString();
 
         SyncJournalFileRecord parentRec;
         propagator()->_journal->getFileRecordByE2eMangledName(relativeRemoteParentPath, &parentRec);
index 80e407f8adcd17404eb065c9e72193a714ef65c9..d91a7d35107f91f4ecd362dd4a806a057474f3f3 100644 (file)
@@ -29,7 +29,8 @@ void PropagateDownloadEncrypted::checkFolderEncryptedStatus()
             return result;
         }
     }();
-    const auto remotePath = QString(rootPath + _item->_file);
+    const auto remoteFilename = _item->_encryptedFileName.isEmpty() ? _item->_file : _item->_encryptedFileName;
+    const auto remotePath = QString(rootPath + remoteFilename);
     const auto remoteParentPath = remotePath.left(remotePath.lastIndexOf('/'));
 
   auto getEncryptedStatus = new GetFolderEncryptStatusJob(_propagator->account(), remoteParentPath, this);
@@ -100,7 +101,9 @@ void PropagateDownloadEncrypted::checkFolderEncryptedMetadata(const QJsonDocumen
   for (const EncryptedFile &file : files) {
     if (encryptedFilename == file.encryptedFilename) {
       _encryptedInfo = file;
-      _item->_encryptedFileName = _item->_file;
+      if (_item->_encryptedFileName.isEmpty()) {
+        _item->_encryptedFileName = _item->_file;
+      }
       if (!_localParentPath.isEmpty()) {
           _item->_file = _localParentPath + QLatin1Char('/') + _encryptedInfo.originalFilename;
       } else {