Better separate between absolute and relative paths on downloads
authorKevin Ottens <kevin.ottens@nextcloud.com>
Mon, 29 Jun 2020 16:20:23 +0000 (18:20 +0200)
committerKevin Ottens (Rebase PR Action) <er-vin@users.noreply.github.com>
Wed, 1 Jul 2020 16:58:29 +0000 (16:58 +0000)
I wish this would be all driven by the type system instead of
error-prone string concatenation everywhere. That will be for a (much)
later refactoring hopefully.

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

index ac417a6227274b705bd76fc2a394b326ea77204f..94f3a99a5c6b9ee5c7b1db615f4c68f4606e06d7 100644 (file)
@@ -359,9 +359,13 @@ 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();
+
         SyncJournalFileRecord parentRec;
-        propagator()->_journal->getFileRecordByE2eMangledName(remoteParentPath, &parentRec);
-        const auto parentPath = parentRec.isValid() ? parentRec._path : remoteParentPath;
+        propagator()->_journal->getFileRecordByE2eMangledName(relativeRemoteParentPath, &parentRec);
+        const auto parentPath = parentRec.isValid() ? parentRec._path : relativeRemoteParentPath;
 
         _downloadEncryptedHelper = new PropagateDownloadEncrypted(propagator(), parentPath, _item, this);
         connect(_downloadEncryptedHelper, &PropagateDownloadEncrypted::folderStatusNotEncrypted, [this] {
index 3b284e9f7888c62bd9853ecfff17e50c9a1e5664..80e407f8adcd17404eb065c9e72193a714ef65c9 100644 (file)
@@ -101,7 +101,11 @@ void PropagateDownloadEncrypted::checkFolderEncryptedMetadata(const QJsonDocumen
     if (encryptedFilename == file.encryptedFilename) {
       _encryptedInfo = file;
       _item->_encryptedFileName = _item->_file;
-      _item->_file = _localParentPath + QLatin1Char('/') + _encryptedInfo.originalFilename;
+      if (!_localParentPath.isEmpty()) {
+          _item->_file = _localParentPath + QLatin1Char('/') + _encryptedInfo.originalFilename;
+      } else {
+          _item->_file = _encryptedInfo.originalFilename;
+      }
 
       qCDebug(lcPropagateDownloadEncrypted) << "Found matching encrypted metadata for file, starting download";
       emit folderStatusEncrypted();
index 9744d64ea4171ff1d359b344f7cf71ac34a8b1ac..b6e1948d111a0c9310f645a7b2d5cf05b65ce228 100644 (file)
@@ -174,9 +174,13 @@ void PropagateLocalMkdir::start()
         !account->e2e()->isFolderEncrypted(remoteParentPath + '/')) {
         startLocalMkdir();
     } else {
+        const auto relativeRemotePath = _item->_file;
+        const auto slashPosition = relativeRemotePath.lastIndexOf('/');
+        const auto relativeRemoteParentPath = slashPosition >= 0 ? relativeRemotePath.left(slashPosition) : QString();
+
         SyncJournalFileRecord parentRec;
-        propagator()->_journal->getFileRecordByE2eMangledName(remoteParentPath, &parentRec);
-        const auto parentPath = parentRec.isValid() ? parentRec._path : remoteParentPath;
+        propagator()->_journal->getFileRecordByE2eMangledName(relativeRemoteParentPath, &parentRec);
+        const auto parentPath = parentRec.isValid() ? parentRec._path : relativeRemoteParentPath;
         startDemanglingName(parentPath);
     }
 }