From 5bc2180478c65e6bf96f390bf1428490b21c6f8f Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Thu, 18 Jul 2019 15:30:40 +0200 Subject: [PATCH] Vfs: Preserve pin state on hydration For #7322 and #7323 --- src/libsync/propagatedownload.cpp | 6 +++--- test/testsyncvirtualfiles.cpp | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index 5bd245c49..d4a68aa04 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -1029,10 +1029,10 @@ void PropagateDownloadFile::downloadFinished() propagator()->_journal->deleteFileRecord(virtualFile); // Move the pin state to the new location - auto pin = propagator()->_journal->internalPinStates().rawForPath(_item->_file.toUtf8()); + auto pin = propagator()->_journal->internalPinStates().rawForPath(virtualFile.toUtf8()); if (pin && *pin != PinState::Inherited) { - vfs->setPinState(virtualFile, *pin); - vfs->setPinState(_item->_file, PinState::Inherited); + vfs->setPinState(_item->_file, *pin); + vfs->setPinState(virtualFile, PinState::Inherited); } } } diff --git a/test/testsyncvirtualfiles.cpp b/test/testsyncvirtualfiles.cpp index 50fa7409d..5bf886f49 100644 --- a/test/testsyncvirtualfiles.cpp +++ b/test/testsyncvirtualfiles.cpp @@ -1162,6 +1162,18 @@ private slots: QVERIFY(fakeFolder.syncOnce()); QCOMPARE(*vfs->pinState("onlinerenamed2/file1rename"), PinState::OnlineOnly); QCOMPARE(*vfs->pinState("onlinerenamed2/file1rename" DVSUFFIX), PinState::OnlineOnly); + + // When a file is hydrated or dehydrated due to pin state it retains its pin state + vfs->setPinState("onlinerenamed2/file1rename" DVSUFFIX, PinState::AlwaysLocal); + QVERIFY(fakeFolder.syncOnce()); + QVERIFY(fakeFolder.currentLocalState().find("onlinerenamed2/file1rename")); + QCOMPARE(*vfs->pinState("onlinerenamed2/file1rename"), PinState::AlwaysLocal); + + vfs->setPinState("onlinerenamed2", PinState::Unspecified); + vfs->setPinState("onlinerenamed2/file1rename", PinState::OnlineOnly); + QVERIFY(fakeFolder.syncOnce()); + QVERIFY(fakeFolder.currentLocalState().find("onlinerenamed2/file1rename" DVSUFFIX)); + QCOMPARE(*vfs->pinState("onlinerenamed2/file1rename" DVSUFFIX), PinState::OnlineOnly); } };