From c10f103fb8a04a91dc80553248764eadae54580b Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Thu, 16 Aug 2018 12:38:39 +0200 Subject: [PATCH] Virtual files: Renaming to virtual doesn't delete data #6718 Unfortunately to do this, the local update phase must write to the database, creating a new side-effect and order dependency (local update must run before remote update). --- src/libsync/propagatedownload.cpp | 2 ++ test/testsyncvirtualfiles.cpp | 36 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index c6a421371..85e9d3867 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -396,6 +396,8 @@ void PropagateDownloadFile::startAfterIsEncryptedIsChecked() if (_item->_type == ItemTypeVirtualFile) { auto fn = propagator()->getFilePath(_item->_file); qCDebug(lcPropagateDownload) << "creating virtual file" << fn; + + // NOTE: Other places might depend on contents of placeholder files (like csync_update) QFile file(fn); file.open(QFile::ReadWrite | QFile::Truncate); file.write(" "); diff --git a/test/testsyncvirtualfiles.cpp b/test/testsyncvirtualfiles.cpp index 422250994..415c90220 100644 --- a/test/testsyncvirtualfiles.cpp +++ b/test/testsyncvirtualfiles.cpp @@ -586,6 +586,42 @@ private slots: QVERIFY(fakeFolder.syncOnce()); QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); } + + void testRenameToVirtual() + { + FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12() }; + SyncOptions syncOptions; + syncOptions._newFilesAreVirtual = true; + fakeFolder.syncEngine().setSyncOptions(syncOptions); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &))); + + auto cleanup = [&]() { + completeSpy.clear(); + }; + cleanup(); + + // If a file is renamed to .owncloud, it becomes virtual + fakeFolder.localModifier().rename("A/a1", "A/a1.owncloud"); + // If a file is renamed to .owncloud, the file sticks around (to preserve user data) + fakeFolder.localModifier().rename("A/a2", "A/rand.owncloud"); + QVERIFY(fakeFolder.syncOnce()); + + QVERIFY(!fakeFolder.currentLocalState().find("A/a1")); + QVERIFY(fakeFolder.currentLocalState().find("A/a1.owncloud")); + QVERIFY(fakeFolder.currentRemoteState().find("A/a1")); + QVERIFY(itemInstruction(completeSpy, "A/a1.owncloud", CSYNC_INSTRUCTION_NEW)); + QCOMPARE(dbRecord(fakeFolder, "A/a1.owncloud")._type, ItemTypeVirtualFile); + + QVERIFY(!fakeFolder.currentLocalState().find("A/a2")); + QVERIFY(!fakeFolder.currentLocalState().find("A/a2.owncloud")); + QVERIFY(fakeFolder.currentLocalState().find("A/rand.owncloud")); + QVERIFY(!fakeFolder.currentRemoteState().find("A/a2")); + QVERIFY(itemInstruction(completeSpy, "A/a2", CSYNC_INSTRUCTION_REMOVE)); + QVERIFY(!dbRecord(fakeFolder, "A/rand.owncloud").isValid()); + + cleanup(); + } }; QTEST_GUILESS_MAIN(TestSyncVirtualFiles) -- 2.30.2