From 8d5c79c2193a28a7b488640b8c855b7cfa4c6d55 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Mon, 29 Jun 2020 18:20:23 +0200 Subject: [PATCH] Better separate between absolute and relative paths on downloads 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 --- src/libsync/propagatedownload.cpp | 8 ++++++-- src/libsync/propagatedownloadencrypted.cpp | 6 +++++- src/libsync/propagatorjobs.cpp | 8 ++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index ac417a622..94f3a99a5 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -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] { diff --git a/src/libsync/propagatedownloadencrypted.cpp b/src/libsync/propagatedownloadencrypted.cpp index 3b284e9f7..80e407f8a 100644 --- a/src/libsync/propagatedownloadencrypted.cpp +++ b/src/libsync/propagatedownloadencrypted.cpp @@ -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(); diff --git a/src/libsync/propagatorjobs.cpp b/src/libsync/propagatorjobs.cpp index 9744d64ea..b6e1948d1 100644 --- a/src/libsync/propagatorjobs.cpp +++ b/src/libsync/propagatorjobs.cpp @@ -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); } }