Skip to content
Draft
2 changes: 1 addition & 1 deletion src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "common/syncjournaldb.h"

Check failure on line 7 in src/gui/folder.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/folder.cpp:7:10 [clang-diagnostic-error]

'common/syncjournaldb.h' file not found
#include "config.h"

#include "account.h"
Expand Down Expand Up @@ -251,7 +251,7 @@

QString Folder::shortGuiRemotePathOrAppName() const
{
if (remotePath().length() > 0 && remotePath() != QLatin1String("/")) {

Check warning on line 254 in src/gui/folder.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use "isEmpty()" to check whether the container is empty or not.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1Xip_6V80h1QdmH4tI&open=AZ1Xip_6V80h1QdmH4tI&pullRequest=9793
QString a = QFile(remotePath()).fileName();
if (a.startsWith('/')) {
a = a.remove(0, 1);
Expand Down Expand Up @@ -337,7 +337,7 @@
return Utility::trailingSlashPath(remotePath());
}

QString Folder::fulllRemotePathToPathInSyncJournalDb(const QString &fullRemotePath) const

Check warning on line 340 in src/gui/folder.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=AZ1Xip_6V80h1QdmH4tJ&open=AZ1Xip_6V80h1QdmH4tJ&pullRequest=9793
{
return Utility::fullRemotePathToRemoteSyncRootRelative(fullRemotePath, remotePathTrailingSlash());
}
Expand Down Expand Up @@ -444,7 +444,7 @@
_lastEtag = etag;
}

void Folder::rootFileIdReceivedFromSyncEngine(const qint64 fileId)

Check warning on line 447 in src/gui/folder.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=AZ1Xip_6V80h1QdmH4tK&open=AZ1Xip_6V80h1QdmH4tK&pullRequest=9793
{
qCDebug(lcFolder).nospace() << "retrieved root fileId=" << fileId;
_rootFileId = fileId;
Expand Down Expand Up @@ -570,7 +570,7 @@
Q_ASSERT(_vfs->mode() == _definition.virtualFilesMode);

const auto result = Vfs::checkAvailability(path(), _vfs->mode());
if (!result) {

Check warning on line 573 in src/gui/folder.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1Xip_6V80h1QdmH4tL&open=AZ1Xip_6V80h1QdmH4tL&pullRequest=9793
_syncResult.appendErrorString(result.error());
_syncResult.setStatus(SyncResult::SetupError);
return;
Expand Down Expand Up @@ -627,7 +627,7 @@
qCInfo(lcFolder) << "Deleting temporary file: " << tmppath;
FileSystem::remove(tmppath);
}
return deleted_infos.size();

Check warning on line 630 in src/gui/folder.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=AZ1Xip_6V80h1QdmH4tG&open=AZ1Xip_6V80h1QdmH4tG&pullRequest=9793
}

int Folder::downloadInfoCount()
Expand All @@ -645,20 +645,20 @@
return _journal.wipeErrorBlacklist();
}

void Folder::slotWatchedPathChanged(const QStringView &path, const ChangeReason reason)

Check failure on line 648 in src/gui/folder.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1Xip_6V80h1QdmH4tN&open=AZ1Xip_6V80h1QdmH4tN&pullRequest=9793
{
if (!path.startsWith(this->path())) {
qCDebug(lcFolder) << "Changed path is not contained in folder, ignoring:" << path;
return;
}

auto relativePath = path.mid(this->path().size());

Check warning on line 655 in src/gui/folder.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "relativePath" of type "class QStringView" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1Xip_6V80h1QdmH4tT&open=AZ1Xip_6V80h1QdmH4tT&pullRequest=9793

if (_vfs) {
if (pathIsIgnored(path.toString())) {
const auto pinState = _vfs->pinState(relativePath.toString());
if ((!pinState || *pinState != PinState::Excluded) && FileSystem::fileExists(relativePath.toString())) {

Check warning on line 660 in src/gui/folder.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1Xip_6V80h1QdmH4tM&open=AZ1Xip_6V80h1QdmH4tM&pullRequest=9793
if (!_vfs->setPinState(relativePath.toString(), PinState::Excluded)) {

Check failure on line 661 in src/gui/folder.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=AZ1Xip_6V80h1QdmH4tO&open=AZ1Xip_6V80h1QdmH4tO&pullRequest=9793
qCWarning(lcFolder) << "Could not set pin state of" << relativePath << "to excluded";
}
}
Expand All @@ -666,7 +666,7 @@
} else {
const auto pinState = _vfs->pinState(relativePath.toString());
if (pinState && *pinState == PinState::Excluded) {
if (!_vfs->setPinState(relativePath.toString(), PinState::Inherited)) {

Check failure on line 669 in src/gui/folder.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=AZ1Xip_6V80h1QdmH4tP&open=AZ1Xip_6V80h1QdmH4tP&pullRequest=9793
qCWarning(lcFolder) << "Could not switch pin state of" << relativePath << "from" << *pinState << "to inherited";
}
}
Expand Down Expand Up @@ -709,13 +709,13 @@
spurious = true;
if (auto pinState = _vfs->pinState(relativePath.toString())) {
qCDebug(lcFolder) << "PinState for" << relativePath << "is" << *pinState;
if (*pinState == PinState::Unspecified) {

Check failure on line 712 in src/gui/folder.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=AZ1Xip_6V80h1QdmH4tQ&open=AZ1Xip_6V80h1QdmH4tQ&pullRequest=9793
spurious = false;
}
if (*pinState == PinState::AlwaysLocal && record.isVirtualFile()) {

Check failure on line 715 in src/gui/folder.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=AZ1Xip_6V80h1QdmH4tR&open=AZ1Xip_6V80h1QdmH4tR&pullRequest=9793
spurious = false;
}
if (*pinState == PinState::OnlineOnly && record.isFile()) {

Check failure on line 718 in src/gui/folder.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=AZ1Xip_6V80h1QdmH4tS&open=AZ1Xip_6V80h1QdmH4tS&pullRequest=9793
spurious = false;
}
} else {
Expand Down Expand Up @@ -947,13 +947,13 @@
removeFromSettings();

auto settings = _accountState->settings();
QString settingsGroup = QStringLiteral("Multifolders");

Check warning on line 950 in src/gui/folder.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the redundant type with "auto".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1Xip_6V80h1QdmH4tU&open=AZ1Xip_6V80h1QdmH4tU&pullRequest=9793

// True if the folder path appears in only one account
const auto folderMap = FolderMan::instance()->map();
const auto oneAccountOnly = std::none_of(folderMap.cbegin(), folderMap.cend(), [this](const auto *other) {
return other != this && other->cleanPath() == this->cleanPath();
});

Check warning on line 956 in src/gui/folder.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=AZ1Xip_6V80h1QdmH4tV&open=AZ1Xip_6V80h1QdmH4tV&pullRequest=9793

if (virtualFilesEnabled() || _saveInFoldersWithPlaceholders) {
// If virtual files are enabled or even were enabled at some point,
Expand Down Expand Up @@ -1010,7 +1010,7 @@
return false;
}

void Folder::appendPathToSelectiveSyncList(const QString &path, const SyncJournalDb::SelectiveSyncListType listType)

Check warning on line 1013 in src/gui/folder.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=AZ1Xip_6V80h1QdmH4tW&open=AZ1Xip_6V80h1QdmH4tW&pullRequest=9793
{
const auto folderPath = Utility::trailingSlashPath(path);
const auto journal = journalDb();
Expand All @@ -1023,7 +1023,7 @@
}
}

void Folder::removePathFromSelectiveSyncList(const QString &path, const SyncJournalDb::SelectiveSyncListType listType)

Check warning on line 1026 in src/gui/folder.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=AZ1Xip_6V80h1QdmH4tX&open=AZ1Xip_6V80h1QdmH4tX&pullRequest=9793
{
const auto folderPath = Utility::trailingSlashPath(path);
const auto journal = journalDb();
Expand Down Expand Up @@ -1063,7 +1063,7 @@
return fileIds.contains(_rootFileId) || journalDb()->hasFileIds(fileIds);
}

QString Folder::filePath(const QString& fileName)

Check warning on line 1066 in src/gui/folder.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=AZ1Xip_6V80h1QdmH4tY&open=AZ1Xip_6V80h1QdmH4tY&pullRequest=9793
{
const auto folderDir = QDir(_canonicalLocalPath);

Expand Down Expand Up @@ -1217,7 +1217,7 @@
}

_engine->setIgnoreHiddenFiles(_definition.ignoreHiddenFiles);
_engine->setFilesystemPermissionsReliable(_folderWatcher->canSetPermissions());
_engine->setFilesystemPermsReliable(_folderWatcher->canSetPermissions());

correctPlaceholderFiles();

Expand Down Expand Up @@ -1246,7 +1246,7 @@
ConfigFile cfgFile;
const auto account = _accountState->account();

auto newFolderLimit = cfgFile.newBigFolderSizeLimit();

Check warning on line 1249 in src/gui/folder.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this declaration by a structured binding declaration.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1Xip_6V80h1QdmH4tZ&open=AZ1Xip_6V80h1QdmH4tZ&pullRequest=9793
opt._newBigFolderSizeLimit = newFolderLimit.first ? newFolderLimit.second * 1000LL * 1000LL : -1; // convert from MB to B
opt._confirmExternalStorage = cfgFile.confirmExternalStorage();
opt._moveFilesToTrash = cfgFile.moveToTrash();
Expand All @@ -1255,7 +1255,7 @@
const auto capsMaxConcurrentChunkUploads = account->capabilities().maxConcurrentChunkUploads();
opt._parallelNetworkJobs = capsMaxConcurrentChunkUploads > 0
? capsMaxConcurrentChunkUploads
: account->isHttp2Supported() ? 20 : 6;

Check warning on line 1258 in src/gui/folder.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested conditional operator into an independent statement.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1Xip_6V80h1QdmH4ta&open=AZ1Xip_6V80h1QdmH4ta&pullRequest=9793

// Chunk V2: Size of chunks must be between 5MB and 5GB, except for the last chunk which can be smaller
const auto cfgMinChunkSize = cfgFile.minChunkSize();
Expand Down Expand Up @@ -1603,7 +1603,7 @@

// If the number of conflicts is too low, adjust it upwards
if (conflictPaths.size() > r.numNewConflictItems() + r.numOldConflictItems())
r.setNumOldConflictItems(conflictPaths.size() - r.numNewConflictItems());

Check warning on line 1606 in src/gui/folder.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=AZ1Xip_6V80h1QdmH4tH&open=AZ1Xip_6V80h1QdmH4tH&pullRequest=9793
}

void Folder::warnOnNewExcludedItem(const SyncJournalFileRecord &record, const QStringView &path)
Expand Down Expand Up @@ -1631,7 +1631,7 @@
return;
}

QFileInfo excludeItemFileInfo(fullPath);

Check warning on line 1634 in src/gui/folder.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "excludeItemFileInfo" of type "class QFileInfo" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1Xip_6V80h1QdmH4tb&open=AZ1Xip_6V80h1QdmH4tb&pullRequest=9793
const auto excludeItemFilePath = excludeItemFileInfo.filePath();
const auto message = FileSystem::isDir(fullPath)
? tr("The folder %1 was created but was excluded from synchronization previously. "
Expand All @@ -1658,21 +1658,21 @@
Logger::instance()->postGuiLog(Theme::instance()->appNameGUI(), fullMessage);
}

void Folder::slotHydrationStarts()

Check warning on line 1661 in src/gui/folder.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=AZ1Xip_6V80h1QdmH4tc&open=AZ1Xip_6V80h1QdmH4tc&pullRequest=9793
{
// // Abort any running full sync run and reschedule
// if (_engine->isSyncRunning()) {
// setSilenceErrorsUntilNextSync(true);
// slotTerminateSync();
// scheduleThisFolderSoon();
// // TODO: This sets the sync state to AbortRequested on done, we don't want that

Check warning on line 1668 in src/gui/folder.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this "TODO" comment.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1Xip_6V80h1QdmH4tF&open=AZ1Xip_6V80h1QdmH4tF&pullRequest=9793
// }

Check warning on line 1669 in src/gui/folder.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the commented out code.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1Xip_6V80h1QdmH4tk&open=AZ1Xip_6V80h1QdmH4tk&pullRequest=9793

// // Let everyone know we're syncing
// _syncResult.reset();
// _syncResult.setStatus(SyncResult::SyncRunning);
// emit syncStarted();
// emit syncStateChange();

Check warning on line 1675 in src/gui/folder.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the commented out code.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1Xip_6V80h1QdmH4tl&open=AZ1Xip_6V80h1QdmH4tl&pullRequest=9793
}

void Folder::slotHydrationDone()
Expand All @@ -1683,7 +1683,7 @@
emit syncStateChange();
}

void Folder::slotHydrationFailed(int errorCode, int statusCode, const QString &errorString, const QString &fileName)

Check warning on line 1686 in src/gui/folder.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=AZ1Xip_6V80h1QdmH4te&open=AZ1Xip_6V80h1QdmH4te&pullRequest=9793

Check warning on line 1686 in src/gui/folder.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1Xip_6V80h1QdmH4td&open=AZ1Xip_6V80h1QdmH4td&pullRequest=9793
{
_syncResult.setStatus(SyncResult::Error);
const auto errorMessageDetails = tr("Virtual file download failed with code \"%1\", status \"%2\" and error message \"%3\"")
Expand All @@ -1692,7 +1692,7 @@
.arg(errorString);
_syncResult.appendErrorString(errorMessageDetails);

const auto errorMessageBox = new VfsDownloadErrorDialog(fileName, errorMessageDetails);

Check failure on line 1695 in src/gui/folder.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the use of "new" with an operation that automatically manages the memory.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1Xip_6V80h1QdmH4tf&open=AZ1Xip_6V80h1QdmH4tf&pullRequest=9793
errorMessageBox->setAttribute(Qt::WA_DeleteOnClose);
errorMessageBox->show();
errorMessageBox->activateWindow();
Expand Down Expand Up @@ -1782,13 +1782,13 @@
const auto isDownDirection = (dir == SyncFileItem::Down);
const QString msg = isDownDirection ? tr("A large number of files in the server have been deleted.\nPlease confirm if you'd like to proceed with these deletions.\nAlternatively, you can restore all deleted files by uploading from '%1' folder to the server.")
: tr("A large number of files in your local '%1' folder have been deleted.\nPlease confirm if you'd like to proceed with these deletions.\nAlternatively, you can restore all deleted files by downloading them from the server.");
auto msgBox = new QMessageBox(QMessageBox::Warning, tr("Remove all files?"),

Check failure on line 1785 in src/gui/folder.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the use of "new" with an operation that automatically manages the memory.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1Xip_6V80h1QdmH4ti&open=AZ1Xip_6V80h1QdmH4ti&pullRequest=9793
msg.arg(shortGuiLocalPath()), QMessageBox::NoButton);

Check warning on line 1786 in src/gui/folder.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "msgBox" of type "class QMessageBox *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1Xip_6V80h1QdmH4th&open=AZ1Xip_6V80h1QdmH4th&pullRequest=9793
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setWindowFlags(msgBox->windowFlags() | Qt::WindowStaysOnTopHint);
msgBox->addButton(tr("Proceed with Deletion"), QMessageBox::DestructiveRole);
QPushButton *keepBtn = msgBox->addButton(isDownDirection ? tr("Restore Files to Server") : tr("Restore Files from Server"),
QMessageBox::AcceptRole);

Check warning on line 1791 in src/gui/folder.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "keepBtn" of type "class QPushButton *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1Xip_6V80h1QdmH4tj&open=AZ1Xip_6V80h1QdmH4tj&pullRequest=9793

Check warning on line 1791 in src/gui/folder.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this variable a pointer-to-const. The current type of "keepBtn" is "class QPushButton *".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1Xip_6V80h1QdmH4tg&open=AZ1Xip_6V80h1QdmH4tg&pullRequest=9793
bool oldPaused = syncPaused();
setSyncPaused(true);
connect(msgBox, &QMessageBox::finished, this, [msgBox, keepBtn, callback, oldPaused, this] {
Expand Down
243 changes: 129 additions & 114 deletions src/libsync/discovery.cpp

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/libsync/discovery.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2018 ownCloud GmbH
Expand All @@ -6,7 +6,7 @@

#pragma once

#include <QObject>

Check failure on line 9 in src/libsync/discovery.h

View workflow job for this annotation

GitHub Actions / build

src/libsync/discovery.h:9:10 [clang-diagnostic-error]

'QObject' file not found
#include <cstdint>
#include "csync_exclude.h"
#include "discoveryphase.h"
Expand Down Expand Up @@ -39,7 +39,7 @@
*
* Results are fed outwards via the DiscoveryPhase::itemDiscovered() signal.
*/
class ProcessDirectoryJob : public QObject

Check warning on line 42 in src/libsync/discovery.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this structure so it has no more than 20 fields, rather than the 21 it currently has.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1UAuJuIWkl5vUdwlRd&open=AZ1UAuJuIWkl5vUdwlRd&pullRequest=9793
{
Q_OBJECT

Expand Down Expand Up @@ -103,7 +103,7 @@
ProcessDirectoryJob *parent);

explicit ProcessDirectoryJob(DiscoveryPhase *data, PinState basePinState, const PathTuple &path, const SyncFileItemPtr &dirItem, const SyncFileItemPtr &parentDirItem,
QueryMode queryLocal, qint64 lastSyncTimestamp, QObject *parent);
const QueryMode queryLocal, qint64 lastSyncTimestamp, QObject *parent);

void start();
/** Start up to nbJobs, return the number of job started; emit finished() when done */
Expand Down Expand Up @@ -204,6 +204,8 @@
*/
MovePermissionResult checkMovePermissions(RemotePermissions srcPerm, const QString &srcPath, bool isDirectory);

void updateDirItemFromServerJob(const DiscoverySingleDirectoryJob *const serverJob);
void applyE2eeEncryptForLocalNew(const SyncFileItemPtr &item, const SyncJournalFileRecord &base) const;
void processBlacklisted(const PathTuple &, const LocalInfo &, const SyncJournalFileRecord &dbEntry);
void subJobFinished();

Expand Down Expand Up @@ -249,8 +251,8 @@
*/
void setupDbPinStateActions(SyncJournalFileRecord &record);

bool maybeRenameForWindowsCompatibility(const QString &absoluteFileName,
CSYNC_EXCLUDE_TYPE excludeReason);
bool maybeRenameForWinCompatibility(const QString &absoluteFileName,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ modernize-use-nodiscard ⚠️
function maybeRenameForWinCompatibility should be marked [[nodiscard]]

Suggested change
bool maybeRenameForWinCompatibility(const QString &absoluteFileName,
[[nodiscard]] bool maybeRenameForWinCompatibility(const QString &absoluteFileName,

const CSYNC_EXCLUDE_TYPE excludeReason) const;

[[nodiscard]] bool checkNewDeleteConflict(const SyncFileItemPtr &item) const;

Expand Down
10 changes: 5 additions & 5 deletions src/libsync/discoveryphase.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2014 ownCloud GmbH
Expand Down Expand Up @@ -113,9 +113,9 @@
explicit DiscoverySingleDirectoryJob(const AccountPtr &account,
const QString &path,
const QString &remoteRootFolderPath,
/* TODO for topLevelE2eeFolderPaths, from review: I still do not get why giving the whole QSet instead of just the parent of the folder we are in
sounds to me like it would be much more efficient to just have the e2ee parent folder that we are
inside*/
// TODO for topLevelE2eeFolderPaths, from review: I still do not get why giving the whole QSet instead of just the parent of the folder we are in

Check warning on line 116 in src/libsync/discoveryphase.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this "TODO" comment.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1XS-Rp0oCGqJGnDPlP&open=AZ1XS-Rp0oCGqJGnDPlP&pullRequest=9793
// sounds to me like it would be much more efficient to just have the e2ee parent folder that we are
// inside
const QSet<QString> &topLevelE2eeFolderPaths,
SyncFileItem::EncryptionStatus parentEncryptionStatus,
QObject *parent = nullptr);
Expand Down Expand Up @@ -295,8 +295,8 @@
ExcludedFiles *_excludes = nullptr;
QRegularExpression _invalidFilenameRx; // FIXME: maybe move in ExcludedFiles
QStringList _serverBlacklistedFiles; // The blacklist from the capabilities
QStringList _leadingAndTrailingSpacesFilesAllowed;
bool _shouldEnforceWindowsFileNameCompatibility = false;
QStringList _spacesFilesAllowed;
bool _enforceWindowsFilenameCompat = false;
bool _ignoreHiddenFiles = false;
std::function<bool(const QString &)> _shouldDiscoverLocaly;

Expand Down
21 changes: 8 additions & 13 deletions src/libsync/propagateupload.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2014 ownCloud GmbH
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "config.h"

Check failure on line 7 in src/libsync/propagateupload.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/propagateupload.cpp:7:10 [clang-diagnostic-error]

'config.h' file not found
#include "propagateupload.h"
#include "propagateuploadencrypted.h"
#include "owncloudpropagator_p.h"
Expand Down Expand Up @@ -71,7 +71,7 @@
qCWarning(lcPutJob) << " Network error: " << reply()->errorString();
}

connect(reply(), &QNetworkReply::uploadProgress, this, [requestID] (qint64 bytesSent, qint64 bytesTotal) {
connect(reply(), &QNetworkReply::uploadProgress, this, [requestID] (const qint64 bytesSent, const qint64 bytesTotal) {
qCDebug(lcPutJob()) << requestID << "upload progress" << bytesSent << bytesTotal;
});

Expand Down Expand Up @@ -114,9 +114,9 @@
_item->_requestId = requestId();
_item->_status = classifyError(err, _item->_httpErrorCode);
_item->_errorString = errorString();
const auto exceptionParsed = getExceptionFromReply(reply());
_item->_errorExceptionName = exceptionParsed.first;
_item->_errorExceptionMessage = exceptionParsed.second;
const auto [exceptionName, exceptionMessage] = getExceptionFromReply(reply());
_item->_errorExceptionName = exceptionName;
_item->_errorExceptionMessage = exceptionMessage;

if (_item->_status == SyncFileItem::FatalError || _item->_httpErrorCode >= 400) {
if (_item->_status != SyncFileItem::FatalError
Expand Down Expand Up @@ -158,10 +158,8 @@
_item->_status = SyncFileItem::Success;
_item->_fileId = json["fileId"].toString().toUtf8();

if (SyncJournalFileRecord oldRecord; _journal->getFileRecord(_item->destination(), &oldRecord) && oldRecord.isValid()) {
if (oldRecord._etag != _item->_etag) {
_item->updateLockStateFromDbRecord(oldRecord);
}
if (SyncJournalFileRecord oldRecord; _journal->getFileRecord(_item->destination(), &oldRecord) && oldRecord.isValid() && oldRecord._etag != _item->_etag) {
_item->updateLockStateFromDbRecord(oldRecord);
}

_item->_etag = parseEtag(json["ETag"].toString().toUtf8());
Expand All @@ -182,9 +180,6 @@

PropagateUploadFileCommon::PropagateUploadFileCommon(OwncloudPropagator *propagator, const SyncFileItemPtr &item)
: PropagateItemJob(propagator, item)
, _finished(false)
, _deleteExisting(false)
, _aborting(false)
{
const auto path = _item->_file;
const auto slashPosition = path.lastIndexOf('/');
Expand Down Expand Up @@ -741,15 +736,15 @@

job->setTimeout(qBound(
// Calculate 3 minutes for each gigabyte of data
qMin(thirtyMinutes - 1, qRound64(threeMinutes * fileSize / 1e9)),
qMin(thirtyMinutes - 1, qRound64(threeMinutes * static_cast<double>(fileSize) / 1e9)),
job->timeoutMsec(),
// Maximum of 30 minutes
thirtyMinutes));
}

void PropagateUploadFileCommon::slotJobDestroyed(QObject *job)
{
_jobs.erase(std::remove(_jobs.begin(), _jobs.end(), job), _jobs.end());
_jobs.erase(std::ranges::remove(_jobs, job).begin(), _jobs.end());
}

// This function is used whenever there is an error occurring and jobs might be in progress
Expand Down
6 changes: 3 additions & 3 deletions src/libsync/propagateupload.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@

protected:
QVector<AbstractNetworkJob *> _jobs; /// network jobs that are currently in transit
bool _finished BITFIELD(1); /// Tells that all the jobs have been finished
bool _deleteExisting BITFIELD(1);
bool _finished BITFIELD(1) = false; /// Tells that all the jobs have been finished
bool _deleteExisting BITFIELD(1) = false;

/** Whether an abort is currently ongoing.
*
* Important to avoid duplicate aborts since each finishing PUTFileJob might
* trigger an abort on error.
*/
bool _aborting BITFIELD(1);
bool _aborting BITFIELD(1) = false;

/* This is a minified version of the SyncFileItem,
* that holds only the specifics about the file that's
Expand Down Expand Up @@ -273,7 +273,7 @@
void slotPollFinished();

protected:
void done(const SyncFileItem::Status status, const QString &errorString = QString(), const ErrorCategory category = ErrorCategory::NoError) override;

Check warning on line 276 in src/libsync/propagateupload.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the default value for parameter "errorString" since the base class does not have a default value.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1U99bBhfkhwAWlg7GG&open=AZ1U99bBhfkhwAWlg7GG&pullRequest=9793

Check warning on line 276 in src/libsync/propagateupload.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the default value for parameter "category" since the base class does not have a default value.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1U99bBhfkhwAWlg7GH&open=AZ1U99bBhfkhwAWlg7GH&pullRequest=9793

/**
* Aborts all running network jobs, except for the ones that mayAbortJob
Expand Down
Loading