Compare commits

...
Author SHA1 Message Date
Matthieu Gallien 013f7b65be feat(vfs/cfapi): mark ignored files as excluded from sync
Windows shows an "excluded" status for files a cloud provider does not
sync. Ignored files in a virtual files folder never got this state:
VfsCfApi::fileStatusChanged() was empty, and the folder watcher checked
whether the file exists using a path relative to the sync folder.

- VfsCfApi::fileStatusChanged() now sets CF_PIN_STATE_EXCLUDED when the
  status tracker reports an existing regular file as excluded.
  Placeholders are skipped, because locked or restored files are
  reported as excluded too.
- The folder watcher checks the absolute path and goes through the same
  fileStatusChanged() call.
- convertToPlaceholder() resets the pin state to inherited before the
  conversion instead of after it. CfConvertToPlaceholder() rejects a
  file pinned as excluded, so a file that stopped being ignored failed
  to sync.

The new tests in testsynccfapi.cpp have not been run successfully yet:
registering the test sync root failed on the development machine for
every test in the suite, including the existing ones.

Signed-off-by: Matthieu Gallien <[email protected]>
Assisted-by: ClaudeCode:claude-opus-5-5
2026-11-06 10:27:21 +01:00
4 changed files with 84 additions and 10 deletions

No files matched your search

+2 -5
View File
@@ -680,11 +680,8 @@ void Folder::slotWatchedPathChanged(const QStringView &path, const ChangeReason
if (_vfs) {
if (pathIsIgnored(path.toString())) {
const auto pinState = _vfs->pinState(relativePath.toString());
if ((!pinState || *pinState != PinState::Excluded) && FileSystem::fileExists(relativePath.toString())) {
if (!_vfs->setPinState(relativePath.toString(), PinState::Excluded)) {
qCWarning(lcFolder) << "Could not set pin state of" << relativePath << "to excluded";
}
if (FileSystem::fileExists(path.toString())) {
_vfs->fileStatusChanged(path.toString(), SyncFileStatus::StatusExcluded);
}
return;
} else {
+6 -3
View File
@@ -1287,6 +1287,11 @@ OCC::CfApiWrapper::convertToPlaceholder(const QString &path, const SyncFileItem
| (item.isDirectory() ? (item._type == ItemType::ItemTypeVirtualDirectory ? CF_CONVERT_FLAG_ENABLE_ON_DEMAND_POPULATION : CF_CONVERT_FLAG_ALWAYS_FULL)
: CF_CONVERT_FLAG_MARK_IN_SYNC);
// An ignored file carries the excluded pin state, which CfConvertToPlaceholder() rejects.
if (const auto stateResult = setPinState(path, PinState::Inherited, NoRecurse); !stateResult) {
return stateResult;
}
const auto result =
CfConvertToPlaceholder(handleForPath(path).get(), fileIdentity.data(), sizeToDWORD(fileIdentitySize), createPlaceholderFlags, nullptr, nullptr);
Q_ASSERT(result == S_OK);
@@ -1304,9 +1309,7 @@ OCC::CfApiWrapper::convertToPlaceholder(const QString &path, const SyncFileItem
return stateResult;
}
}
const auto stateResult = setPinState(path, PinState::Inherited, NoRecurse);
Q_ASSERT(stateResult);
return stateResult;
return OCC::Vfs::ConvertToPlaceholderResult::Ok;
}
OCC::Result<OCC::Vfs::ConvertToPlaceholderResult, QString>
+13 -2
View File
@@ -499,8 +499,19 @@ void VfsCfApi::requestHydration(const QString &requestId, const QString &path)
void VfsCfApi::fileStatusChanged(const QString &systemFileName, SyncFileStatus fileStatus)
{
Q_UNUSED(systemFileName);
Q_UNUSED(fileStatus);
if (fileStatus.tag() != SyncFileStatus::StatusExcluded) {
return;
}
// A placeholder was synced before and is only reported as excluded while it is locked or being restored.
const auto localPath = QDir::toNativeSeparators(systemFileName);
if (!FileSystem::fileExists(localPath) || cfapi::findPlaceholderInfo(localPath)) {
return;
}
if (!setPinStateLocal(localPath, PinState::Excluded)) {
qCWarning(lcCfApi) << "Could not set pin state of" << localPath << "to excluded";
}
}
void VfsCfApi::scheduleHydrationJob(const QString &requestId, const QString &folderPath, const SyncJournalFileRecord &record)
+63
View File
@@ -65,6 +65,14 @@ void setPinState(const QString &path, PinState state, cfapi::SetPinRecurseMode m
}
}
bool hasExcludedPinState(const QString &path)
{
// CfGetPlaceholderInfo() fails on regular files, so read the attributes that encode CF_PIN_STATE_EXCLUDED.
const auto attributes = GetFileAttributesW(reinterpret_cast<const wchar_t *>(QDir::toNativeSeparators(path).utf16()));
constexpr auto excludedAttributes = DWORD{FILE_ATTRIBUTE_PINNED | FILE_ATTRIBUTE_UNPINNED};
return attributes != INVALID_FILE_ATTRIBUTES && (attributes & excludedAttributes) == excludedAttributes;
}
bool itemInstruction(const ItemCompletedSpy &spy, const QString &path, const SyncInstructions instr)
{
auto item = spy.findItem(path);
@@ -1175,6 +1183,61 @@ private Q_SLOTS:
QCOMPARE(*vfs->pinState("onlinerenamed2/file1rename"), PinState::OnlineOnly);
}
void testIgnoredFileGetsExcludedPinState()
{
FakeFolder fakeFolder{FileInfo()};
setupVfs(fakeFolder);
fakeFolder.syncEngine().excludedFiles().addManualExclude(u"*.ignored"_s);
fakeFolder.localModifier().mkdir(u"A"_s);
fakeFolder.localModifier().insert(u"A/foo.ignored"_s);
fakeFolder.localModifier().insert(u"A/bar"_s);
QVERIFY(fakeFolder.syncOnce());
QVERIFY(!fakeFolder.currentRemoteState().find(u"A/foo.ignored"_s));
QVERIFY(hasExcludedPinState(fakeFolder.localPath() + u"A/foo.ignored"_s));
QVERIFY(!hasExcludedPinState(fakeFolder.localPath() + u"A/bar"_s));
QVERIFY(!hasExcludedPinState(fakeFolder.localPath() + u"A"_s));
}
void testFileNoLongerIgnoredSyncs()
{
FakeFolder fakeFolder{FileInfo()};
auto vfs = setupVfs(fakeFolder);
fakeFolder.syncEngine().excludedFiles().addManualExclude(u"*.ignored"_s);
fakeFolder.localModifier().insert(u"foo.ignored"_s);
QVERIFY(fakeFolder.syncOnce());
QVERIFY(hasExcludedPinState(fakeFolder.localPath() + u"foo.ignored"_s));
// The renamed file keeps its attributes, so it must lose the excluded pin state when it gets converted.
fakeFolder.localModifier().rename(u"foo.ignored"_s, u"foo"_s);
QVERIFY(fakeFolder.syncOnce());
QVERIFY(fakeFolder.currentRemoteState().find(u"foo"_s));
CFVERIFY_NONVIRTUAL(fakeFolder, u"foo"_s);
QVERIFY(!hasExcludedPinState(fakeFolder.localPath() + u"foo"_s));
QCOMPARE(*vfs->pinState(u"foo"_s), PinState::Inherited);
}
void testExcludedStatusDoesNotChangePlaceholderPinState()
{
FakeFolder fakeFolder{FileInfo()};
auto vfs = setupVfs(fakeFolder);
fakeFolder.localModifier().insert(u"foo"_s);
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(*vfs->pinState(u"foo"_s), PinState::Inherited);
// Locked or restored placeholders are reported as excluded too.
vfs->fileStatusChanged(fakeFolder.localPath() + u"foo"_s, SyncFileStatus::StatusExcluded);
QCOMPARE(*vfs->pinState(u"foo"_s), PinState::Inherited);
// A path that does not exist (anymore) is skipped.
vfs->fileStatusChanged(fakeFolder.localPath() + u"missing"_s, SyncFileStatus::StatusExcluded);
QVERIFY(!QFileInfo::exists(fakeFolder.localPath() + u"missing"_s));
}
void testEmptyFolderInOnlineOnlyRoot()
{
FakeFolder fakeFolder{ FileInfo() };