From: Kevin Ottens Date: Tue, 30 Jun 2020 14:04:55 +0000 (+0200) Subject: Better separate between absolute and relative paths on uploads X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~222^2^2~125^2~5 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=3204c1591150b955bdb69ff2b75d23c3820cf5b9;p=nextcloud-desktop.git Better separate between absolute and relative paths on uploads Yes... I still wish this would be all driven by the type system, would be much less error-prone. Signed-off-by: Kevin Ottens --- diff --git a/src/libsync/propagateremotemkdir.cpp b/src/libsync/propagateremotemkdir.cpp index cd6bfdb1c..636369880 100644 --- a/src/libsync/propagateremotemkdir.cpp +++ b/src/libsync/propagateremotemkdir.cpp @@ -111,8 +111,9 @@ void PropagateRemoteMkdir::slotMkdir() return result; } }(); - const auto path = QString(rootPath + _item->_file); - const auto parentPath = path.left(path.lastIndexOf('/')); + const auto path = _item->_file; + const auto slashPosition = path.lastIndexOf('/'); + const auto parentPath = slashPosition >= 0 ? path.left(slashPosition) : QString(); SyncJournalFileRecord parentRec; bool ok = propagator()->_journal->getFileRecord(parentPath, &parentRec); @@ -122,11 +123,12 @@ void PropagateRemoteMkdir::slotMkdir() } const auto remoteParentPath = parentRec._e2eMangledName.isEmpty() ? parentPath : parentRec._e2eMangledName; + const auto absoluteRemoteParentPath = remoteParentPath.isEmpty() ? rootPath : rootPath + remoteParentPath + '/'; const auto account = propagator()->account(); if (!account->capabilities().clientSideEncryptionAvailable() || - (!account->e2e()->isFolderEncrypted(remoteParentPath + '/') && - !account->e2e()->isAnyParentFolderEncrypted(remoteParentPath + '/'))) { + (!account->e2e()->isFolderEncrypted(absoluteRemoteParentPath) && + !account->e2e()->isAnyParentFolderEncrypted(absoluteRemoteParentPath))) { slotStartMkcolJob(); return; } diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp index 89cfb7343..3a90e0906 100644 --- a/src/libsync/propagateupload.cpp +++ b/src/libsync/propagateupload.cpp @@ -179,8 +179,9 @@ void PropagateUploadFileCommon::start() return result; } }(); - const auto path = QString(rootPath + _item->_file); - const auto parentPath = path.left(path.lastIndexOf('/')); + const auto path = _item->_file; + const auto slashPosition = path.lastIndexOf('/'); + const auto parentPath = slashPosition >= 0 ? path.left(slashPosition) : QString(); SyncJournalFileRecord parentRec; bool ok = propagator()->_journal->getFileRecord(parentPath, &parentRec); @@ -190,10 +191,11 @@ void PropagateUploadFileCommon::start() } const auto remoteParentPath = parentRec._e2eMangledName.isEmpty() ? parentPath : parentRec._e2eMangledName; + const auto absoluteRemoteParentPath = remoteParentPath.isEmpty() ? rootPath : rootPath + remoteParentPath + '/'; const auto account = propagator()->account(); if (!account->capabilities().clientSideEncryptionAvailable() || - !account->e2e()->isFolderEncrypted(remoteParentPath + '/')) { + !account->e2e()->isFolderEncrypted(absoluteRemoteParentPath)) { setupUnencryptedFile(); return; }