mirror of
https://github.com/chylex/Nextcloud-Desktop.git
synced 2025-05-28 08:34:02 +02:00
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).
This commit is contained in:
parent
a670431a48
commit
c10f103fb8
@ -396,6 +396,8 @@ void PropagateDownloadFile::startAfterIsEncryptedIsChecked()
|
|||||||
if (_item->_type == ItemTypeVirtualFile) {
|
if (_item->_type == ItemTypeVirtualFile) {
|
||||||
auto fn = propagator()->getFilePath(_item->_file);
|
auto fn = propagator()->getFilePath(_item->_file);
|
||||||
qCDebug(lcPropagateDownload) << "creating virtual file" << fn;
|
qCDebug(lcPropagateDownload) << "creating virtual file" << fn;
|
||||||
|
|
||||||
|
// NOTE: Other places might depend on contents of placeholder files (like csync_update)
|
||||||
QFile file(fn);
|
QFile file(fn);
|
||||||
file.open(QFile::ReadWrite | QFile::Truncate);
|
file.open(QFile::ReadWrite | QFile::Truncate);
|
||||||
file.write(" ");
|
file.write(" ");
|
||||||
|
@ -586,6 +586,42 @@ private slots:
|
|||||||
QVERIFY(fakeFolder.syncOnce());
|
QVERIFY(fakeFolder.syncOnce());
|
||||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
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)
|
QTEST_GUILESS_MAIN(TestSyncVirtualFiles)
|
||||||
|
Loading…
Reference in New Issue
Block a user