From: Christian Kamm Date: Fri, 21 Jun 2019 07:39:33 +0000 (+0200) Subject: Vfs: Move pin state if files move #7250 X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~227 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=fb47419e84b03f1ed35b0f38ac294f180c80abe4;p=nextcloud-desktop.git Vfs: Move pin state if files move #7250 Previously renames of items didn't carry the pin state with them. --- diff --git a/src/common/vfs.cpp b/src/common/vfs.cpp index 2265d5410..745f66a3b 100644 --- a/src/common/vfs.cpp +++ b/src/common/vfs.cpp @@ -70,7 +70,8 @@ bool Vfs::setPinStateInDb(const QString &folderPath, PinState state) { auto path = folderPath.toUtf8(); _setupParams.journal->internalPinStates().wipeForPathAndBelow(path); - _setupParams.journal->internalPinStates().setForPath(path, state); + if (state != PinState::Inherited) + _setupParams.journal->internalPinStates().setForPath(path, state); return true; } diff --git a/src/libsync/propagateremotemove.cpp b/src/libsync/propagateremotemove.cpp index 952668fa8..889fb7b1d 100644 --- a/src/libsync/propagateremotemove.cpp +++ b/src/libsync/propagateremotemove.cpp @@ -199,13 +199,19 @@ void PropagateRemoteMove::slotMoveJobFinished() void PropagateRemoteMove::finalize() { - SyncJournalFileRecord oldRecord; - propagator()->_journal->getFileRecord(_item->_originalFile, &oldRecord); + // Retrieve old db data. // if reading from db failed still continue hoping that deleteFileRecord // reopens the db successfully. // The db is only queried to transfer the content checksum from the old // to the new record. It is not a problem to skip it here. + SyncJournalFileRecord oldRecord; + propagator()->_journal->getFileRecord(_item->_originalFile, &oldRecord); + auto &vfs = propagator()->syncOptions()._vfs; + auto pinState = vfs->pinState(_item->_originalFile); + + // Delete old db data. propagator()->_journal->deleteFileRecord(_item->_originalFile); + vfs->setPinState(_item->_originalFile, PinState::Inherited); SyncFileItem newItem(*_item); newItem._type = _item->_type; @@ -222,6 +228,11 @@ void PropagateRemoteMove::finalize() done(SyncFileItem::FatalError, tr("Error writing metadata to the database")); return; } + if (pinState && *pinState != PinState::Inherited + && !vfs->setPinState(newItem._renameTarget, *pinState)) { + done(SyncFileItem::NormalError, tr("Error setting pin state")); + return; + } if (_item->isDirectory()) { propagator()->_renamedDirectories.insert(_item->_file, _item->_renameTarget); diff --git a/src/libsync/propagatorjobs.cpp b/src/libsync/propagatorjobs.cpp index a5a864bfd..8324e6f3a 100644 --- a/src/libsync/propagatorjobs.cpp +++ b/src/libsync/propagatorjobs.cpp @@ -283,6 +283,10 @@ void PropagateLocalRename::start() propagator()->_journal->getFileRecord(_item->_originalFile, &oldRecord); propagator()->_journal->deleteFileRecord(_item->_originalFile); + auto &vfs = propagator()->syncOptions()._vfs; + auto pinState = vfs->pinState(_item->_originalFile); + vfs->setPinState(_item->_originalFile, PinState::Inherited); + const auto oldFile = _item->_file; if (!_item->isDirectory()) { // Directories are saved at the end @@ -301,6 +305,11 @@ void PropagateLocalRename::start() return; } } + if (pinState && *pinState != PinState::Inherited + && !vfs->setPinState(_item->_renameTarget, *pinState)) { + done(SyncFileItem::NormalError, tr("Error setting pin state")); + return; + } propagator()->_journal->commit("localRename"); diff --git a/test/testsyncvirtualfiles.cpp b/test/testsyncvirtualfiles.cpp index adf0b4822..d4efc9304 100644 --- a/test/testsyncvirtualfiles.cpp +++ b/test/testsyncvirtualfiles.cpp @@ -1128,6 +1128,26 @@ private slots: // Sync again: bad pin states of new local files usually take effect on second sync QVERIFY(fakeFolder.syncOnce()); QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + + // When a file in an online-only folder is renamed, it retains its pin + fakeFolder.localModifier().rename("online/file1", "online/file1rename"); + fakeFolder.remoteModifier().rename("online/file2", "online/file2rename"); + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(*vfs->pinState("online/file1rename"), PinState::Unspecified); + QCOMPARE(*vfs->pinState("online/file2rename"), PinState::Unspecified); + + // When a folder is renamed, the pin states inside should be retained + fakeFolder.localModifier().rename("online", "onlinerenamed1"); + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(*vfs->pinState("onlinerenamed1"), PinState::OnlineOnly); + QCOMPARE(*vfs->pinState("onlinerenamed1/file1rename"), PinState::Unspecified); + + fakeFolder.remoteModifier().rename("onlinerenamed1", "onlinerenamed2"); + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(*vfs->pinState("onlinerenamed2"), PinState::OnlineOnly); + QCOMPARE(*vfs->pinState("onlinerenamed2/file1rename"), PinState::Unspecified); + + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); } };