Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions src/gui/folderman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
namespace {
constexpr auto settingsAccountsC = "Accounts";
constexpr auto settingsFoldersC = "Folders";
constexpr auto settingsFoldersWithPlaceholdersC = "FoldersWithPlaceholders";

Check warning on line 42 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this identifier to be shorter or equal to 31 characters.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWw5&open=AZ-T1BrB18-5KNpaJWw5&pullRequest=10445
constexpr auto settingsVersionC = "version";
constexpr auto maxFoldersVersion = 1;

int numberOfSyncJournals(const QString &path)
{
return QDir(path).entryList({ QStringLiteral(".sync_*.db"), QStringLiteral("._sync_*.db") }, QDir::Hidden | QDir::Files).size();

Check warning on line 48 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

implicit conversion loses integer precision: 'qsizetype' (aka 'long long') to 'int'

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWw2&open=AZ-T1BrB18-5KNpaJWw2&pullRequest=10445
}

}
Expand Down Expand Up @@ -108,7 +108,7 @@
return _folderMap;
}

void FolderMan::unloadFolder(Folder *f)

Check warning on line 111 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this parameter a pointer-to-const. The current type of "f" is "class OCC::Folder *".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWw6&open=AZ-T1BrB18-5KNpaJWw6&pullRequest=10445
{
if (!f) {
return;
Expand Down Expand Up @@ -227,7 +227,7 @@
folder->processSwitchedToVirtualFiles();
}

return _folderMap.size();

Check warning on line 230 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

implicit conversion loses integer precision: 'size_type' (aka 'long long') to 'int'

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWw3&open=AZ-T1BrB18-5KNpaJWw3&pullRequest=10445
}

void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account, const QStringList &ignoreKeys, bool backwardsCompatible, bool foldersWithPlaceholders)
Expand Down Expand Up @@ -453,14 +453,14 @@
emit folderListChanged(_folderMap);

// return the number of valid folders.
return _folderMap.size();

Check warning on line 456 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

implicit conversion loses integer precision: 'size_type' (aka 'long long') to 'int'

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWw4&open=AZ-T1BrB18-5KNpaJWw4&pullRequest=10445
}

void FolderMan::backwardMigrationSettingsKeys(QStringList *deleteKeys, QStringList *ignoreKeys)
{
auto settings = ConfigFile::settingsWithGroup(QLatin1String("Accounts"));

auto processSubgroup = [&](const QString &name) {

Check warning on line 463 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This lambda has 21 lines, which is greater than the 20 lines authorized. Split it into several lambdas or functions, or make it a named function.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWw7&open=AZ-T1BrB18-5KNpaJWw7&pullRequest=10445
settings->beginGroup(name);
const auto foldersVersion = settings->value(QLatin1String(settingsVersionC), 1).toInt();
qCInfo(lcFolderMan) << "FolderDefinition::maxSettingsVersion:" << FolderDefinition::maxSettingsVersion();
Expand Down Expand Up @@ -567,7 +567,7 @@
return a;
}

void FolderMan::setupLegacyFolder(const QString &fileNamePath, AccountState *accountState)

Check warning on line 570 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "accountState" of type "class OCC::AccountState *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWw-&open=AZ-T1BrB18-5KNpaJWw-&pullRequest=10445

Check failure on line 570 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 45 to the 25 allowed.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWw8&open=AZ-T1BrB18-5KNpaJWw8&pullRequest=10445
{
qCInfo(lcFolderMan) << " ` -> setting up:" << fileNamePath;
QString escapedFileNamePath(fileNamePath);
Expand Down Expand Up @@ -602,7 +602,7 @@
return;
}

auto migrateFoldersGroup = [&](const QString &folderGroupName) {

Check warning on line 605 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This lambda has 84 lines, which is greater than the 20 lines authorized. Split it into several lambdas or functions, or make it a named function.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWw_&open=AZ-T1BrB18-5KNpaJWw_&pullRequest=10445
const auto childGroups = settings.childGroups();
if (childGroups.isEmpty()) {
qCDebug(lcFolderMan) << "There are no" << folderGroupName << "to migrate from account" << accountState->account()->id();
Expand Down Expand Up @@ -682,7 +682,7 @@
legacyBlacklist << settings.value(QLatin1String("blackList")).toStringList();
if (!legacyBlacklist.isEmpty()) {
qCInfo(lcFolderMan) << "Legacy selective sync list found:" << legacyBlacklist;
for (const auto &legacyFolder : std::as_const(legacyBlacklist)) {

Check failure on line 685 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWw9&open=AZ-T1BrB18-5KNpaJWw9&pullRequest=10445
folder->migrateBlackListPath(legacyFolder);
}
settings.remove(QLatin1String("blackList"));
Expand Down Expand Up @@ -745,7 +745,7 @@

void FolderMan::slotFolderCanSyncChanged()
{
auto folder = qobject_cast<Folder *>(sender());

Check warning on line 748 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "folder" of type "class OCC::Folder *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxA&open=AZ-T1BrB18-5KNpaJWxA&pullRequest=10445
ASSERT(folder);
if (folder->canSync()) {
_socketApi->slotRegisterPath(folder->alias());
Expand Down Expand Up @@ -1046,7 +1046,7 @@
void FolderMan::slotStartScheduledFolderSync()
{
if (isAnySyncRunning()) {
for (auto f : std::as_const(_folderMap)) {

Check warning on line 1049 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "f" of type "class OCC::Folder *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxB&open=AZ-T1BrB18-5KNpaJWxB&pullRequest=10445
if (f->isSyncRunning())
qCInfo(lcFolderMan) << "Currently folder " << f->remoteUrl().toString() << " is running, wait for finish!";
}
Expand Down Expand Up @@ -1087,7 +1087,7 @@
}
}

bool FolderMan::pushNotificationsFilesReady(const AccountPtr &account)

Check warning on line 1090 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This function should be declared "const".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxC&open=AZ-T1BrB18-5KNpaJWxC&pullRequest=10445
{
const auto pushNotifications = account->pushNotifications();
const auto pushFilesAvailable = account->capabilities().availablePushNotifications() & PushNotificationType::Files;
Expand All @@ -1109,6 +1109,13 @@
return result;
}

#ifdef BUILD_FILE_PROVIDER_MODULE
bool FolderMan::canPollFileProviderEtag(const AccountState &accountState)
{
return accountState.isConnected();
}
#endif

void FolderMan::slotEtagPollTimerTimeout()
{
qCInfo(lcFolderMan) << "Etag poll timer timeout";
Expand All @@ -1120,10 +1127,10 @@
QList<Folder *> foldersToRun;

// Some folders need not to be checked because they use the push notifications
std::copy_if(folderMapValues.begin(), folderMapValues.end(), std::back_inserter(foldersToRun), [this](Folder *folder) -> bool {
const auto account = folder->accountState()->account();
return !pushNotificationsFilesReady(account);
});

Check warning on line 1133 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace with the version of "std::ranges::copy_if" that takes a range.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxD&open=AZ-T1BrB18-5KNpaJWxD&pullRequest=10445

qCInfo(lcFolderMan) << "Number of folders that don't use push notifications:" << foldersToRun.size();

Expand All @@ -1139,6 +1146,11 @@
for (const auto &accountState : accounts) {
const auto account = accountState->account();

if (!canPollFileProviderEtag(*accountState)) {
qCDebug(lcFolderMan) << "Account" << account->displayName() << "is not connected, skipping File Provider ETag check.";
continue;
}

// Skip accounts that don't have a File Provider domain
if (!Mac::FileProvider::instance()->domainManager()->domainForAccount(account.data())) {
qCDebug(lcFolderMan) << "Account" << account->displayName() << "has no file provider domain, skipping.";
Expand Down Expand Up @@ -1425,9 +1437,9 @@
// Migration: The first account that's configured for a local folder shall
// be saved in a backwards-compatible way.
const auto folderList = FolderMan::instance()->map();
const auto oneAccountOnly = std::none_of(folderList.cbegin(), folderList.cend(), [folder](const auto *other) {
return other != folder && other->cleanPath() == folder->cleanPath();
});

Check warning on line 1442 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace with the version of "std::ranges::none_of" that takes a range.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxE&open=AZ-T1BrB18-5KNpaJWxE&pullRequest=10445

folder->setSaveBackwardsCompatible(oneAccountOnly);

Expand Down Expand Up @@ -1494,10 +1506,10 @@
QString absolutePath = QDir::cleanPath(path) + QLatin1Char('/');

const auto folders = this->map().values();
const auto it = std::find_if(folders.cbegin(), folders.cend(), [absolutePath](const auto *folder) {
const QString folderPath = folder->cleanPath() + QLatin1Char('/');
return absolutePath.startsWith(folderPath, (Utility::isWindows() || Utility::isMac()) ? Qt::CaseInsensitive : Qt::CaseSensitive);
});

Check warning on line 1512 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace with the version of "std::ranges::find_if" that takes a range.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxF&open=AZ-T1BrB18-5KNpaJWxF&pullRequest=10445

return it != folders.cend() ? *it : nullptr;
}
Expand Down Expand Up @@ -1560,7 +1572,7 @@
return re;
}

void FolderMan::removeFolder(Folder *folderToRemove)

Check warning on line 1575 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "folderToRemove" of type "class OCC::Folder *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxG&open=AZ-T1BrB18-5KNpaJWxG&pullRequest=10445
{
if (!folderToRemove) {
qCCritical(lcFolderMan) << "Can not remove null folder";
Expand Down Expand Up @@ -1596,7 +1608,7 @@
// Let the folder delete itself when done.
connect(folderToRemove, &Folder::syncFinished, folderToRemove, &QObject::deleteLater);
} else {
delete folderToRemove;

Check failure on line 1611 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rewrite the code so that you no longer need this "delete".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxH&open=AZ-T1BrB18-5KNpaJWxH&pullRequest=10445
}

#ifdef Q_OS_WIN
Expand Down Expand Up @@ -1641,7 +1653,7 @@
f->wipeForRemoval();

// wipe data
QDir userFolder(f->path());

Check warning on line 1656 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "userFolder" of type "class QDir" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxI&open=AZ-T1BrB18-5KNpaJWxI&pullRequest=10445
if (userFolder.exists()) {
success = FileSystem::removeRecursively(f->path());
if (!success) {
Expand Down Expand Up @@ -1719,8 +1731,8 @@
const auto filePathRelative = Utility::noLeadingSlashPath(QString(localFileNoTrailingSlash).remove(folder->path()));

SyncJournalFileRecord rec;
if (folder->journalDb()->getFileRecord(filePathRelative, &rec)
&& rec.isValid() && rec.isE2eEncrypted()) {

Check warning on line 1735 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the init-statement to declare "rec" inside the if statement.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxJ&open=AZ-T1BrB18-5KNpaJWxJ&pullRequest=10445
qCWarning(lcFolderMan) << "You cannot remove yourself from an encrypted share";
return;
}
Expand All @@ -1741,17 +1753,17 @@
const auto leaveShareJob = new SimpleApiJob(folder->accountState()->account(), folder->accountState()->account()->davPath() + filePathRelative);
leaveShareJob->setVerb(SimpleApiJob::Verb::Delete);
leaveShareJob->addRawHeader("e2e-token", folderToken);
connect(leaveShareJob, &SimpleApiJob::resultReceived, this, [this, folder, localFile](int statusCode) {

Check warning on line 1756 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "statusCode" of type "int" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxL&open=AZ-T1BrB18-5KNpaJWxL&pullRequest=10445

Check warning on line 1756 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the unused lambda capture "localFile".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxK&open=AZ-T1BrB18-5KNpaJWxK&pullRequest=10445
qCDebug(lcFolderMan) << "slotLeaveShare callback statusCode" << statusCode;
Q_UNUSED(statusCode);

Check warning on line 1758 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Modify the macro definition so that it needs to be followed by a semicolon, or remove this empty statement.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxM&open=AZ-T1BrB18-5KNpaJWxM&pullRequest=10445
scheduleFolder(folder);
});
leaveShareJob->start();
}

void FolderMan::trayOverallStatus(const QList<Folder *> &folders,
SyncResult::Status *status,

Check warning on line 1765 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "status" of type "enum OCC::SyncResult::Status *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxN&open=AZ-T1BrB18-5KNpaJWxN&pullRequest=10445
bool *unresolvedConflicts,

Check warning on line 1766 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "unresolvedConflicts" of type "_Bool *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxO&open=AZ-T1BrB18-5KNpaJWxO&pullRequest=10445
ProgressInfo **const overallProgressInfo)
{
*status = SyncResult::Undefined;
Expand Down Expand Up @@ -1854,7 +1866,7 @@
}
}

QString FolderMan::trayTooltipStatusString(SyncResult::Status syncStatus, bool hasUnresolvedConflicts, bool paused, ProgressInfo *const progress)

Check warning on line 1869 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "syncStatus" of type "enum OCC::SyncResult::Status" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxT&open=AZ-T1BrB18-5KNpaJWxT&pullRequest=10445

Check warning on line 1869 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "paused" of type "_Bool" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxV&open=AZ-T1BrB18-5KNpaJWxV&pullRequest=10445

Check failure on line 1869 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 34 to the 25 allowed.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxP&open=AZ-T1BrB18-5KNpaJWxP&pullRequest=10445

Check warning on line 1869 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "hasUnresolvedConflicts" of type "_Bool" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxU&open=AZ-T1BrB18-5KNpaJWxU&pullRequest=10445

Check warning on line 1869 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this parameter a pointer-to-const. The current type of "progress" is "class OCC::ProgressInfo *const".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxS&open=AZ-T1BrB18-5KNpaJWxS&pullRequest=10445
{
QString folderMessage;
switch (syncStatus) {
Expand All @@ -1867,13 +1879,13 @@
case SyncResult::SyncPrepare:
folderMessage = tr("Preparing for sync.");
break;
case SyncResult::SyncRunning:

Check warning on line 1882 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Reduce this switch case number of lines from 31 to at most 5, for example by extracting code into methods.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxW&open=AZ-T1BrB18-5KNpaJWxW&pullRequest=10445
if (progress && progress->status() == ProgressInfo::Propagation) {
const auto estimatedEta = progress->totalProgress().estimatedEta;
if (progress->totalSize() == 0) {
qint64 currentFile = progress->currentFile();

Check warning on line 1886 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "currentFile" of type "long long" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxX&open=AZ-T1BrB18-5KNpaJWxX&pullRequest=10445
qint64 totalFileCount = qMax(progress->totalFiles(), currentFile);

Check warning on line 1887 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "totalFileCount" of type "long long" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxY&open=AZ-T1BrB18-5KNpaJWxY&pullRequest=10445
if (progress->trustEta()) {

Check failure on line 1888 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxQ&open=AZ-T1BrB18-5KNpaJWxQ&pullRequest=10445
if (estimatedEta == 0) {
folderMessage = tr("Syncing %1 of %2 (A few seconds left)").arg(currentFile).arg(totalFileCount);
} else {
Expand All @@ -1885,7 +1897,7 @@
}
} else {
QString totalSizeStr = Utility::octetsToString(progress->totalSize());
if (progress->trustEta()) {

Check failure on line 1900 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxR&open=AZ-T1BrB18-5KNpaJWxR&pullRequest=10445
if (estimatedEta == 0) {
folderMessage = tr("Syncing %1 (A few seconds left)").arg(totalSizeStr);
} else {
Expand Down Expand Up @@ -1943,7 +1955,7 @@

if (!FileSystem::fileExists(path)) {
QString parentPath = selFile.dir().path();
if (parentPath != path) {

Check warning on line 1958 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the init-statement to declare "parentPath" inside the if statement.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxZ&open=AZ-T1BrB18-5KNpaJWxZ&pullRequest=10445
return checkPathValidityRecursive(parentPath);
}

Expand Down Expand Up @@ -2147,7 +2159,7 @@
{
qCDebug(lcFolderMan) << "received notify_file push notification account=" << account->displayName();

for (auto folder : std::as_const(_folderMap)) {

Check warning on line 2162 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "folder" of type "class OCC::Folder *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxa&open=AZ-T1BrB18-5KNpaJWxa&pullRequest=10445
// Just run on the folders that belong to this account
if (folder->accountState()->account() != account) {
continue;
Expand All @@ -2158,11 +2170,11 @@
}
}

void FolderMan::slotProcessFileIdsPushNotification(Account *account, const QList<qint64> &fileIds)

Check warning on line 2173 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this identifier to be shorter or equal to 31 characters.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxb&open=AZ-T1BrB18-5KNpaJWxb&pullRequest=10445

Check warning on line 2173 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "account" of type "class OCC::Account *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxc&open=AZ-T1BrB18-5KNpaJWxc&pullRequest=10445
{
qCDebug(lcFolderMan).nospace() << "received notify_file_id push notification account=" << account->displayName() << " fileIds=" << fileIds;

for (auto folder : std::as_const(_folderMap)) {

Check warning on line 2177 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "folder" of type "class OCC::Folder *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxd&open=AZ-T1BrB18-5KNpaJWxd&pullRequest=10445
// Just run on the folders that belong to this account
if (folder->accountState()->account() != account) {
continue;
Expand All @@ -2189,7 +2201,7 @@
}
}

bool FolderMan::checkVfsAvailability(const QString &path, Vfs::Mode mode) const

Check warning on line 2204 in src/gui/folderman.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "mode" of type "enum OCC::Vfs::Mode" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-T1BrB18-5KNpaJWxe&open=AZ-T1BrB18-5KNpaJWxe&pullRequest=10445
{
return unsupportedConfiguration(path) && Vfs::checkAvailability(path, mode);
}
Expand Down
5 changes: 5 additions & 0 deletions src/gui/folderman.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef FOLDERMAN_H
#define FOLDERMAN_H

#include <QByteArray>

Check failure on line 10 in src/gui/folderman.h

View workflow job for this annotation

GitHub Actions / build

src/gui/folderman.h:10:10 [clang-diagnostic-error]

'QByteArray' file not found
#include <QObject>
#include <QQueue>
#include <QList>
Expand Down Expand Up @@ -36,7 +36,7 @@
class SyncResult;
class SocketApi;
class LockWatcher;
class UpdateE2eeFolderUsersMetadataJob;

Check warning on line 39 in src/gui/folderman.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this identifier to be shorter or equal to 31 characters.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-UTNknmWohWZGgzqHC&open=AZ-UTNknmWohWZGgzqHC&pullRequest=10445

/**
* @brief The FolderMan class
Expand Down Expand Up @@ -228,10 +228,10 @@
/** removes current user from the share **/
void leaveShare(const QString &localFile);

/** Whether or not vfs is supported in the location. */

Check warning on line 231 in src/gui/folderman.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Edit this comment to use the C++ format, i.e. "//".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-UTNknmWohWZGgzqHA&open=AZ-UTNknmWohWZGgzqHA&pullRequest=10445
[[nodiscard]] bool checkVfsAvailability(const QString &path, Vfs::Mode mode = bestAvailableVfsMode()) const;

/** If the folder configuration is no longer supported this will return an error string */

Check warning on line 234 in src/gui/folderman.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Edit this comment to use the C++ format, i.e. "//".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-UTNknmWohWZGgzqHB&open=AZ-UTNknmWohWZGgzqHB&pullRequest=10445
[[nodiscard]] Result<void, QString> unsupportedConfiguration(const QString &path) const;
signals:
/**
Expand Down Expand Up @@ -328,7 +328,7 @@

void slotSetupPushNotifications(const OCC::Folder::Map &);
void slotProcessFilesPushNotification(OCC::Account *account);
void slotProcessFileIdsPushNotification(OCC::Account *account, const QList<qint64> &fileIds);

Check warning on line 331 in src/gui/folderman.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this identifier to be shorter or equal to 31 characters.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ-UTNknmWohWZGgzqHD&open=AZ-UTNknmWohWZGgzqHD&pullRequest=10445
void slotConnectToPushNotifications(const OCC::AccountPtr &account);

void slotLeaveShare(const QString &localFile, const QByteArray &folderToken = {});
Expand Down Expand Up @@ -357,6 +357,11 @@
void runEtagJobsIfPossible(const QList<Folder *> &folderMap);
void runEtagJobIfPossible(Folder *folder);

#ifdef BUILD_FILE_PROVIDER_MODULE
/** @brief Returns whether the account state permits File Provider ETag polling. */
[[nodiscard]] static bool canPollFileProviderEtag(const AccountState &accountState);
#endif

bool pushNotificationsFilesReady(const OCC::AccountPtr &account);

[[nodiscard]] bool isSwitchToVfsNeeded(const FolderDefinition &folderDefinition) const;
Expand Down
24 changes: 24 additions & 0 deletions test/testfolderman.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud GmbH
Expand All @@ -8,7 +8,7 @@
* any purpose.
*/

#include <qglobal.h>

Check failure on line 11 in test/testfolderman.cpp

View workflow job for this annotation

GitHub Actions / build

test/testfolderman.cpp:11:10 [clang-diagnostic-error]

'qglobal.h' file not found
#include <QTemporaryDir>
#include <QtTest>

Expand Down Expand Up @@ -609,6 +609,30 @@
}

#ifdef BUILD_FILE_PROVIDER_MODULE
void testFileProviderEtagPollingRequiresConnectedAccount()
{
const auto accountState = std::make_unique<FakeAccountState>(Account::create());
QVERIFY(FolderMan::canPollFileProviderEtag(*accountState));

const auto disconnectedStates = {
AccountState::SignedOut,
AccountState::Disconnected,
AccountState::ServiceUnavailable,
AccountState::RedirectDetected,
AccountState::MaintenanceMode,
AccountState::NetworkError,
AccountState::ConfigurationError,
AccountState::AskingCredentials,
AccountState::NeedToSignTermsOfService,
};

for (const auto state : disconnectedStates) {
accountState->setStateForTesting(state);
QVERIFY2(!FolderMan::canPollFileProviderEtag(*accountState),
qPrintable(AccountState::stateString(state)));
}
}

void testAddFolderRefusedWhenFileProviderModeEnabled()
{
_fm.reset({});
Expand Down
Loading