Stop using e2e()->isFolderEncrypted() in the jobs
authorKevin Ottens <kevin.ottens@nextcloud.com>
Mon, 7 Dec 2020 17:42:24 +0000 (18:42 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:59:22 +0000 (10:59 +0100)
Thanks to the new discovery algorithm, we got all the freshest E2EE
information straight from the database so reuse it instead of going
through an in memory copy.

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

index f3348a152bdf86d9e93ea79de7fe7b0407f9017e..f56fdcd3da050faa72522f9ad8f824f6c0b2412f 100644 (file)
@@ -367,27 +367,19 @@ void PropagateDownloadFile::start()
 
     qCDebug(lcPropagateDownload) << _item->_file << propagator()->_activeJobList.count();
 
-    const auto rootPath = [=]() {
-        const auto result = propagator()->remotePath();
-        if (result.startsWith('/')) {
-            return result.mid(1);
-        } else {
-            return result;
-        }
-    }();
-    const auto remoteFilename = _item->_encryptedFileName.isEmpty() ? _item->_file : _item->_encryptedFileName;
-    const auto remotePath = QString(rootPath + remoteFilename);
-    const auto remoteParentPath = remotePath.left(remotePath.lastIndexOf('/'));
+    const auto path = _item->_file;
+    const auto slashPosition = path.lastIndexOf('/');
+    const auto parentPath = slashPosition >= 0 ? path.left(slashPosition) : QString();
+
+    SyncJournalFileRecord parentRec;
+    propagator()->_journal->getFileRecord(parentPath, &parentRec);
 
     const auto account = propagator()->account();
     if (!account->capabilities().clientSideEncryptionAvailable() ||
-        !account->e2e()->isFolderEncrypted(remoteParentPath + '/')) {
+        !parentRec.isValid() ||
+        !parentRec._isE2eEncrypted) {
         startAfterIsEncryptedIsChecked();
     } else {
-        const auto path = _item->_file;
-        const auto slashPosition = path.lastIndexOf('/');
-        const auto parentPath = slashPosition >= 0 ? path.left(slashPosition) : QString();
-
         _downloadEncryptedHelper = new PropagateDownloadEncrypted(propagator(), parentPath, _item, this);
         connect(_downloadEncryptedHelper, &PropagateDownloadEncrypted::folderStatusNotEncrypted, [this] {
           startAfterIsEncryptedIsChecked();
index ca18c04c32ab1246f4c198e1092d6a271e123c2d..2f67b9af3074904e3f614d43a32dd6264d90fbb7 100644 (file)
@@ -52,12 +52,11 @@ PropagateRemoteMkdir::PropagateRemoteMkdir(OwncloudPropagator *propagator, const
         return;
     }
 
-    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(absoluteRemoteParentPath)) {
+        parentRec.isValid() &&
+        parentRec._isE2eEncrypted) {
         _parallelism = WaitForFinished;
     }
 }
@@ -162,18 +161,27 @@ void PropagateRemoteMkdir::slotMkdir()
         return;
     }
 
-    const auto remoteParentPath = parentRec._e2eMangledName.isEmpty() ? parentPath : parentRec._e2eMangledName;
-    const auto absoluteRemoteParentPath = remoteParentPath.isEmpty() ? rootPath : rootPath + remoteParentPath + '/';
-    const auto account = propagator()->account();
+    const auto hasEncryptedAncestor = [=] {
+        auto pathComponents = parentPath.split('/');
+        while (!pathComponents.isEmpty()) {
+            SyncJournalFileRecord rec;
+            propagator()->_journal->getFileRecord(pathComponents.join('/'), &rec);
+            if (rec.isValid() && rec._isE2eEncrypted) {
+                return true;
+            }
+            pathComponents.removeLast();
+        }
+        return false;
+    }();
 
-    if (!account->capabilities().clientSideEncryptionAvailable() ||
-        (!account->e2e()->isFolderEncrypted(absoluteRemoteParentPath) &&
-         !account->e2e()->isAnyParentFolderEncrypted(absoluteRemoteParentPath))) {
+    const auto account = propagator()->account();
+    if (!account->capabilities().clientSideEncryptionAvailable() || !hasEncryptedAncestor) {
         slotStartMkcolJob();
         return;
     }
 
     // We should be encrypted as well since our parent is
+    const auto remoteParentPath = parentRec._e2eMangledName.isEmpty() ? parentPath : parentRec._e2eMangledName;
     _uploadEncryptedHelper = new PropagateUploadEncrypted(propagator(), remoteParentPath, _item, this);
     connect(_uploadEncryptedHelper, &PropagateUploadEncrypted::folderNotEncrypted,
       this, &PropagateRemoteMkdir::slotStartMkcolJob);
index 1229110378eeae89f29a7058133f111593b8ee3f..6c8af7f1f6ccd98909b0c62323e5a829519334ff 100644 (file)
@@ -196,14 +196,6 @@ PropagateUploadFileCommon::PropagateUploadFileCommon(OwncloudPropagator *propaga
     , _uploadEncryptedHelper(nullptr)
     , _uploadingEncrypted(false)
 {
-    const auto rootPath = [=]() {
-        const auto result = propagator->remotePath();
-        if (result.startsWith('/')) {
-            return result.mid(1);
-        } else {
-            return result;
-        }
-    }();
     const auto path = _item->_file;
     const auto slashPosition = path.lastIndexOf('/');
     const auto parentPath = slashPosition >= 0 ? path.left(slashPosition) : QString();
@@ -214,12 +206,11 @@ PropagateUploadFileCommon::PropagateUploadFileCommon(OwncloudPropagator *propaga
         return;
     }
 
-    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(absoluteRemoteParentPath)) {
+        parentRec.isValid() &&
+        parentRec._isE2eEncrypted) {
         _parallelism = WaitForFinished;
     }
 }
@@ -236,14 +227,6 @@ void PropagateUploadFileCommon::setDeleteExisting(bool enabled)
 
 void PropagateUploadFileCommon::start()
 {
-    const auto rootPath = [=]() {
-        const auto result = propagator()->remotePath();
-        if (result.startsWith('/')) {
-            return result.mid(1);
-        } else {
-            return result;
-        }
-    }();
     const auto path = _item->_file;
     const auto slashPosition = path.lastIndexOf('/');
     const auto parentPath = slashPosition >= 0 ? path.left(slashPosition) : QString();
@@ -255,16 +238,16 @@ void PropagateUploadFileCommon::start()
         return;
     }
 
-    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(absoluteRemoteParentPath)) {
+        !parentRec.isValid() ||
+        !parentRec._isE2eEncrypted) {
         setupUnencryptedFile();
         return;
     }
 
+    const auto remoteParentPath = parentRec._e2eMangledName.isEmpty() ? parentPath : parentRec._e2eMangledName;
     _uploadEncryptedHelper = new PropagateUploadEncrypted(propagator(), remoteParentPath, _item, this);
     connect(_uploadEncryptedHelper, &PropagateUploadEncrypted::folderNotEncrypted,
             this, &PropagateUploadFileCommon::setupUnencryptedFile);