Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
013f7b65be |
No files matched your search
+2
-5
@@ -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 {
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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() };
|
||||
|
||||
Reference in new issue
Block a user