From 34dc5e4e88bb2fef848d6708459336eeab101b80 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Fri, 21 Jun 2019 09:06:07 +0200 Subject: [PATCH] Vfs: Don't let new local files start out unpinned #7250 If one adds a new file to an online-only folder the previous behavior was to upload the file in one sync and dehydrate it in the next. Now these new files get set to Unspecified pin state, making them retain their data. --- src/libsync/propagateupload.cpp | 11 ++++++++++ test/testsyncvirtualfiles.cpp | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp index 2b043f358..3f3df353e 100644 --- a/src/libsync/propagateupload.cpp +++ b/src/libsync/propagateupload.cpp @@ -780,6 +780,17 @@ void PropagateUploadFileCommon::finalize() return; } + // Files that were new on the remote shouldn't have online-only pin state + // even if their parent folder is online-only. + if (_item->_instruction == CSYNC_INSTRUCTION_NEW + || _item->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE) { + auto &vfs = propagator()->syncOptions()._vfs; + const auto pin = vfs->pinState(_item->_file); + if (pin && *pin == PinState::OnlineOnly) { + vfs->setPinState(_item->_file, PinState::Unspecified); + } + } + // Remove from the progress database: propagator()->_journal->setUploadInfo(_item->_file, SyncJournalDb::UploadInfo()); propagator()->_journal->commit("upload file start"); diff --git a/test/testsyncvirtualfiles.cpp b/test/testsyncvirtualfiles.cpp index b13d085fd..adf0b4822 100644 --- a/test/testsyncvirtualfiles.cpp +++ b/test/testsyncvirtualfiles.cpp @@ -1090,6 +1090,45 @@ private slots: QVERIFY(!r); QCOMPARE(r.error(), Vfs::AvailabilityError::NoSuchItem); } + + void testPinStateLocals() + { + FakeFolder fakeFolder{ FileInfo() }; + auto vfs = setupVfs(fakeFolder); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + + auto setPin = [&] (const QByteArray &path, PinState state) { + fakeFolder.syncJournal().internalPinStates().setForPath(path, state); + }; + + fakeFolder.remoteModifier().mkdir("local"); + fakeFolder.remoteModifier().mkdir("online"); + fakeFolder.remoteModifier().mkdir("unspec"); + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + + setPin("local", PinState::AlwaysLocal); + setPin("online", PinState::OnlineOnly); + setPin("unspec", PinState::Unspecified); + + fakeFolder.localModifier().insert("file1"); + fakeFolder.localModifier().insert("online/file1"); + fakeFolder.localModifier().insert("online/file2"); + fakeFolder.localModifier().insert("local/file1"); + fakeFolder.localModifier().insert("unspec/file1"); + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + + // root is unspecified + QCOMPARE(*vfs->pinState("file1"), PinState::Unspecified); + QCOMPARE(*vfs->pinState("local/file1"), PinState::AlwaysLocal); + QCOMPARE(*vfs->pinState("online/file1"), PinState::Unspecified); + QCOMPARE(*vfs->pinState("unspec/file1"), PinState::Unspecified); + + // Sync again: bad pin states of new local files usually take effect on second sync + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + } }; QTEST_GUILESS_MAIN(TestSyncVirtualFiles) -- 2.30.2