1
0
mirror of https://github.com/chylex/Nextcloud-Desktop.git synced 2025-05-06 14:34:09 +02:00

Virtual files: Renaming to virtual doesn't delete data

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).
This commit is contained in:
Christian Kamm 2018-08-16 12:38:39 +02:00 committed by Kevin Ottens
parent a670431a48
commit c10f103fb8
No known key found for this signature in database
GPG Key ID: 074BBBCB8DECC9E2
2 changed files with 38 additions and 0 deletions

View File

@ -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(" ");

View File

@ -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 <name>.owncloud, it becomes virtual
fakeFolder.localModifier().rename("A/a1", "A/a1.owncloud");
// If a file is renamed to <random>.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)