Better separate between absolute and relative paths on uploads
authorKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 30 Jun 2020 14:04:55 +0000 (16:04 +0200)
committerKevin Ottens (Rebase PR Action) <er-vin@users.noreply.github.com>
Wed, 1 Jul 2020 16:58:29 +0000 (16:58 +0000)
Yes... I still wish this would be all driven by the type system, would be
much less error-prone.

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

index cd6bfdb1cfa82fcd4597ac689033d181a5038cc9..6363698803e9e5718ad16aa91cb33a0f1be5369f 100644 (file)
@@ -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;
     }
index 89cfb7343f8fa227d2aefe16fa3248876fada587..3a90e0906d4ba45b39e40565a046e2a2aad8a5cc 100644 (file)
@@ -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;
     }