The e2eMangledName was relative to the remote folder, repair it
authorKevin Ottens <kevin.ottens@nextcloud.com>
Mon, 1 Feb 2021 15:52:12 +0000 (16:52 +0100)
committerallexzander (Rebase PR Action) <allexzander@users.noreply.github.com>
Thu, 4 Feb 2021 11:16:48 +0000 (11:16 +0000)
This got broken during the huge discovery refactoring. I wrongly passed
the mangled name as is out of discovery, but coming from listing jobs it
was fully qualified while the jobs at propagation time and the db expect
those paths to be relative to the remote folder.

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

index dbc90bd040e5c60827f56d3c76939d19c203d440..6c025460005f9eae487729846e2092c7e6f41ce8 100644 (file)
@@ -163,7 +163,13 @@ void ProcessDirectoryJob::process()
 
         // On the server the path is mangled in case of E2EE
         if (!e.serverEntry.e2eMangledName.isEmpty()) {
-            path._server = e.serverEntry.e2eMangledName;
+            Q_ASSERT(_discoveryData->_remoteFolder.startsWith('/'));
+            Q_ASSERT(_discoveryData->_remoteFolder.endsWith('/'));
+
+            const auto rootPath = _discoveryData->_remoteFolder.mid(1);
+            Q_ASSERT(e.serverEntry.e2eMangledName.startsWith(rootPath));
+
+            path._server = e.serverEntry.e2eMangledName.mid(rootPath.length());
         }
 
         // If the filename starts with a . we consider it a hidden file
@@ -398,8 +404,19 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(
     item->_etag = serverEntry.etag;
     item->_directDownloadUrl = serverEntry.directDownloadUrl;
     item->_directDownloadCookies = serverEntry.directDownloadCookies;
-    item->_encryptedFileName = serverEntry.e2eMangledName;
     item->_isEncrypted = serverEntry.isE2eEncrypted;
+    item->_encryptedFileName = [=] {
+        if (serverEntry.e2eMangledName.isEmpty()) {
+            return QString();
+        }
+
+        Q_ASSERT(_discoveryData->_remoteFolder.startsWith('/'));
+        Q_ASSERT(_discoveryData->_remoteFolder.endsWith('/'));
+
+        const auto rootPath = _discoveryData->_remoteFolder.mid(1);
+        Q_ASSERT(serverEntry.e2eMangledName.startsWith(rootPath));
+        return serverEntry.e2eMangledName.mid(rootPath.length());
+    }();
 
     // Check for missing server data
     {