Merge pull request #8111 from nextcloud/bugfix/pinstate

fix(PinState): don't trigger sync when file's PinState changed to Unspecified.
This commit is contained in:
Matthieu Gallien 2025-04-15 10:30:18 +02:00 committed by GitHub
commit 5e2fa24b2e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 1 deletions

View File

@ -652,8 +652,11 @@ void Folder::slotWatchedPathChanged(const QStringView &path, const ChangeReason
if (record.isValid()
&& !FileSystem::fileChanged(path.toString(), record._fileSize, record._modtime) && _vfs) {
spurious = true;
if (auto pinState = _vfs->pinState(relativePath.toString())) {
qCDebug(lcFolder) << "PinState for" << relativePath << "is" << *pinState;
if (*pinState == PinState::Unspecified) {
spurious = false;
}
if (*pinState == PinState::AlwaysLocal && record.isVirtualFile()) {
spurious = false;
}

View File

@ -1449,6 +1449,43 @@ private slots:
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}
void testDetectSpuriousNotification() {
#if !defined Q_OS_WIN
QSKIP("not applicable");
#endif
FakeFolder fakeFolder{FileInfo{}};
auto vfs = setupVfs(fakeFolder);
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
const QString odpFile("odp/presentation.odp");
const QString odtFile("odt/document.odt");
fakeFolder.localModifier().mkdir("odp");
fakeFolder.localModifier().insert(odpFile);
fakeFolder.localModifier().mkdir("odt");
fakeFolder.localModifier().insert(odtFile);
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
ItemCompletedSpy completeSpy(fakeFolder);
QFile odp(fakeFolder.localPath() + odpFile);
QVERIFY(odp.open(QIODevice::ReadWrite));
odp.write(odpFile.toLatin1(), qstrlen(odpFile.toLatin1()));
odp.close();
QVERIFY(fakeFolder.syncOnce());
QVERIFY(itemInstruction(completeSpy, odpFile, CSYNC_INSTRUCTION_SYNC));
QCOMPARE(*vfs->pinState(odpFile), PinState::Unspecified);
QFile odt(fakeFolder.localPath() + odtFile);
QVERIFY(odt.open(QIODevice::ReadWrite));
odt.close();
QVERIFY(fakeFolder.syncOnce());
QVERIFY(itemInstruction(completeSpy, odtFile, CSYNC_INSTRUCTION_UPDATE_METADATA));
QCOMPARE(*vfs->pinState(odtFile), PinState::Unspecified);
}
};
QTEST_GUILESS_MAIN(TestSyncCfApi)