From b8bebab2eb59ce0b9b7b0f921bffeccea8deaffc Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Mon, 6 Mar 2023 16:28:55 +0100 Subject: [PATCH 1/4] add assert to prevent upload of virtual files Signed-off-by: Matthieu Gallien --- src/libsync/propagateupload.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp index 832999d75a3fd..b834c024b035e 100644 --- a/src/libsync/propagateupload.cpp +++ b/src/libsync/propagateupload.cpp @@ -255,6 +255,8 @@ void PropagateUploadFileCommon::setupUnencryptedFile() } void PropagateUploadFileCommon::startUploadFile() { + Q_ASSERT(_item->_type != CSyncEnums::ItemTypeVirtualFile); + if (propagator()->_abortRequested) { return; } From 9afd7265bb46ba6c176760353121a2212165e4b2 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Mon, 6 Mar 2023 16:27:57 +0100 Subject: [PATCH 2/4] add a new automated test for virtual files and data restoration add a test that will try to upload pure virtual files becase restoration after server data fingerprint has changed this is illegal and should not happen Signed-off-by: Matthieu Gallien --- test/testsyncvirtualfiles.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/testsyncvirtualfiles.cpp b/test/testsyncvirtualfiles.cpp index 1dd091dbda85b..a4ce8c8c66ce6 100644 --- a/test/testsyncvirtualfiles.cpp +++ b/test/testsyncvirtualfiles.cpp @@ -1880,6 +1880,32 @@ private slots: conflicts = findCaseClashConflicts(*fakeFolder.currentLocalState().find("a/b")); QCOMPARE(conflicts.size(), shouldHaveCaseClashConflict ? 1 : 0); } + + void testDataFingerPrint() + { + FakeFolder fakeFolder{ FileInfo{} }; + setupVfs(fakeFolder); + + fakeFolder.remoteModifier().mkdir("a"); + fakeFolder.remoteModifier().mkdir("a/b"); + fakeFolder.remoteModifier().mkdir("a/b/d"); + fakeFolder.remoteModifier().insert("a/b/otherFile.txt"); + + //Server support finger print, but none is set. + fakeFolder.remoteModifier().extraDavProperties = ""; + + fakeFolder.syncEngine().setLocalDiscoveryOptions(OCC::LocalDiscoveryStyle::DatabaseAndFilesystem); + QVERIFY(fakeFolder.syncOnce()); + + fakeFolder.remoteModifier().remove("a/b/otherFile.txt"); + fakeFolder.remoteModifier().remove("a/b/d"); + fakeFolder.remoteModifier().extraDavProperties = "initial_finger_print"; + + fakeFolder.syncEngine().setLocalDiscoveryOptions(OCC::LocalDiscoveryStyle::DatabaseAndFilesystem); + QVERIFY(fakeFolder.syncOnce()); + + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + } }; QTEST_GUILESS_MAIN(TestSyncVirtualFiles) From baf9c8b631315c8ae1e8a916e087b1a0fe2672ab Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Mon, 6 Mar 2023 18:16:50 +0100 Subject: [PATCH 3/4] add test for windows CfApi Signed-off-by: Matthieu Gallien --- test/testsynccfapi.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/testsynccfapi.cpp b/test/testsynccfapi.cpp index 4b06b6e15cc72..95dd076ffc38f 100644 --- a/test/testsynccfapi.cpp +++ b/test/testsynccfapi.cpp @@ -1218,6 +1218,32 @@ private slots: CFVERIFY_VIRTUAL(fakeFolder, "online/sub/file1"); } } + + void testDataFingerPrint() + { + FakeFolder fakeFolder{ FileInfo{} }; + setupVfs(fakeFolder); + + fakeFolder.remoteModifier().mkdir("a"); + fakeFolder.remoteModifier().mkdir("a/b"); + fakeFolder.remoteModifier().mkdir("a/b/d"); + fakeFolder.remoteModifier().insert("a/b/otherFile.txt"); + + //Server support finger print, but none is set. + fakeFolder.remoteModifier().extraDavProperties = ""; + + fakeFolder.syncEngine().setLocalDiscoveryOptions(OCC::LocalDiscoveryStyle::DatabaseAndFilesystem); + QVERIFY(fakeFolder.syncOnce()); + + fakeFolder.remoteModifier().remove("a/b/otherFile.txt"); + fakeFolder.remoteModifier().remove("a/b/d"); + fakeFolder.remoteModifier().extraDavProperties = "initial_finger_print"; + + fakeFolder.syncEngine().setLocalDiscoveryOptions(OCC::LocalDiscoveryStyle::DatabaseAndFilesystem); + QVERIFY(fakeFolder.syncOnce()); + + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + } }; QTEST_GUILESS_MAIN(TestSyncCfApi) From cbf7ba78ad6482614a4e579fc5b129c2cf168109 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Mon, 6 Mar 2023 16:40:17 +0100 Subject: [PATCH 4/4] prevent restoration of files that are not plain old files would prevent trying to restore pure virtual files Signed-off-by: Matthieu Gallien --- src/libsync/syncengine.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index b74b05bf3a95c..23c41be9e991b 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -992,9 +992,11 @@ void SyncEngine::restoreOldFiles(SyncFileItemVector &syncItems) syncItem->_instruction = CSYNC_INSTRUCTION_CONFLICT; break; case CSYNC_INSTRUCTION_REMOVE: - qCWarning(lcEngine) << "restoreOldFiles: RESTORING" << syncItem->_file; - syncItem->_instruction = CSYNC_INSTRUCTION_NEW; - syncItem->_direction = SyncFileItem::Up; + if (syncItem->_type != CSyncEnums::ItemTypeVirtualFile && syncItem->_type != CSyncEnums::ItemTypeVirtualFileDownload) { + qCWarning(lcEngine) << "restoreOldFiles: RESTORING" << syncItem->_file; + syncItem->_instruction = CSYNC_INSTRUCTION_NEW; + syncItem->_direction = SyncFileItem::Up; + } break; case CSYNC_INSTRUCTION_RENAME: case CSYNC_INSTRUCTION_NEW: