From: Kevin Ottens Date: Mon, 7 Dec 2020 17:42:24 +0000 (+0100) Subject: Stop using e2e()->isFolderEncrypted() in the jobs X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~41 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=7a4a3597045d3d52943ad52fc58c61936a35ecc4;p=nextcloud-desktop.git Stop using e2e()->isFolderEncrypted() in the jobs 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 --- diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index f3348a152..f56fdcd3d 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -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(); diff --git a/src/libsync/propagateremotemkdir.cpp b/src/libsync/propagateremotemkdir.cpp index ca18c04c3..2f67b9af3 100644 --- a/src/libsync/propagateremotemkdir.cpp +++ b/src/libsync/propagateremotemkdir.cpp @@ -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); diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp index 122911037..6c8af7f1f 100644 --- a/src/libsync/propagateupload.cpp +++ b/src/libsync/propagateupload.cpp @@ -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);