Previously renames of items didn't carry the pin state with them.
{
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;
}
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;
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);
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
return;
}
}
+ if (pinState && *pinState != PinState::Inherited
+ && !vfs->setPinState(_item->_renameTarget, *pinState)) {
+ done(SyncFileItem::NormalError, tr("Error setting pin state"));
+ return;
+ }
propagator()->_journal->commit("localRename");
// 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());
}
};