Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-3.14] better logs to understand when a folder is locally discovered #7342

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 36 additions & 11 deletions src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/libsync/syncengine.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/libsync/syncengine.cpp

File src/libsync/syncengine.cpp does not conform to Custom style guidelines. (lines 1215, 1216)
* Copyright (C) by Duncan Mac-Vicar P. <[email protected]>
* Copyright (C) by Klaas Freitag <[email protected]>
*
Expand Down Expand Up @@ -648,7 +648,6 @@
_discoveryPhase->_syncOptions = _syncOptions;
_discoveryPhase->_shouldDiscoverLocaly = [this](const QString &path) {
const auto result = shouldDiscoverLocally(path);
qCDebug(lcEngine) << "shouldDiscoverLocaly" << path << (result ? "true" : "false");
return result;
};
_discoveryPhase->setSelectiveSyncBlackList(selectiveSyncBlackList);
Expand Down Expand Up @@ -1213,6 +1212,13 @@
_localDiscoveryStyle = style;
_localDiscoveryPaths = std::move(paths);

const auto allPaths = std::accumulate(_localDiscoveryPaths.begin(), _localDiscoveryPaths.end(), QString{}, [] (auto first, auto second) -> QString {
first += ", " + second;
return first;
});

qCInfo(lcEngine()) << "paths to discover locally" << allPaths;

// Normalize to make sure that no path is a contained in another.
// Note: for simplicity, this code consider anything less than '/' as a path separator, so for
// example, this will remove "foo.bar" if "foo" is in the list. This will mean we might have
Expand Down Expand Up @@ -1242,8 +1248,12 @@

bool SyncEngine::shouldDiscoverLocally(const QString &path) const
{
if (_localDiscoveryStyle == LocalDiscoveryStyle::FilesystemOnly)
return true;
auto result = false;

if (_localDiscoveryStyle == LocalDiscoveryStyle::FilesystemOnly) {
result = true;
return result;
}

// The intention is that if "A/X" is in _localDiscoveryPaths:
// - parent folders like "/", "A" will be discovered (to make sure the discovery reaches the
Expand All @@ -1257,25 +1267,40 @@
if (it == _localDiscoveryPaths.end() || !it->startsWith(path)) {
// Maybe a subfolder of something in the list?
if (it != _localDiscoveryPaths.begin() && path.startsWith(*(--it))) {
return it->endsWith('/') || (path.size() > it->size() && path.at(it->size()) <= '/');
result = it->endsWith('/') || (path.size() > it->size() && path.at(it->size()) <= '/');
if (!result) {
qCInfo(lcEngine()) << path << "no local discovery needed";
}
return result;
}
return false;
result = false;
qCInfo(lcEngine()) << path << "no local discovery needed";
return result;
}

// maybe an exact match or an empty path?
if (it->size() == path.size() || path.isEmpty())
if (it->size() == path.size() || path.isEmpty()) {
return true;
}

// Maybe a parent folder of something in the list?
// check for a prefix + / match
forever {
if (it->size() > path.size() && it->at(path.size()) == '/')
return true;
if (it->size() > path.size() && it->at(path.size()) == '/') {
result = true;
return result;
}

++it;
if (it == _localDiscoveryPaths.end() || !it->startsWith(path))
return false;
if (it == _localDiscoveryPaths.end() || !it->startsWith(path)) {
result = false;
qCInfo(lcEngine()) << path << "no local discovery needed";
return result;
}
}
return false;

qCInfo(lcEngine()) << path << "no local discovery needed";
return result;
}

void SyncEngine::wipeVirtualFiles(const QString &localPath, SyncJournalDb &journal, Vfs &vfs)
Expand Down
Loading