Skip to content
Open
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
9 changes: 9 additions & 0 deletions src/csync/csync_exclude.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* libcsync -- a library to sync a directory with another
*
Expand All @@ -7,7 +7,7 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
*/

#include "config_csync.h"

Check failure on line 10 in src/csync/csync_exclude.cpp

View workflow job for this annotation

GitHub Actions / build

src/csync/csync_exclude.cpp:10:10 [clang-diagnostic-error]

'config_csync.h' file not found
#include <qglobal.h>

#ifndef _GNU_SOURCE
Expand All @@ -27,6 +27,9 @@
#include <QFileInfo>
#include <QDir>
#include <QVariant>
#include <QLoggingCategory>

Q_LOGGING_CATEGORY(lcCsyncExclude, "nextcloud.csync.exclude", QtInfoMsg)

Check warning on line 32 in src/csync/csync_exclude.cpp

View workflow job for this annotation

GitHub Actions / build

src/csync/csync_exclude.cpp:32:1 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'Q_LOGGING_CATEGORY' is non-const and globally accessible, consider making it const

/** Expands C-like escape sequences (in place)
*/
Expand Down Expand Up @@ -81,7 +84,7 @@
* @param file_name filename
* @return true if file is reserved, false otherwise
*/
OCSYNC_EXPORT bool csync_is_windows_reserved_word(const QStringView &filename)

Check failure on line 87 in src/csync/csync_exclude.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1uNDb1s0Fbzs2jIOwz&open=AZ1uNDb1s0Fbzs2jIOwz&pullRequest=9810
{
size_t len_filename = filename.size();

Expand Down Expand Up @@ -163,10 +166,16 @@
// not allow to sync those to avoid file loss/ambiguities (#416)
if (blen > 1) {
if (bname.at(blen - 1) == QLatin1Char('.')) {

return CSYNC_FILE_EXCLUDE_INVALID_CHAR;
}
}

if (OCC::FileSystem::isFileLocked(path, OCC::FileSystem::LockMode::SharedRead)) {
qCWarning(lcCsyncExclude) << path << "is locked" << "exluding it from sync";
return CSYNC_FILE_SILENTLY_EXCLUDED;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The CSYNC_EXCLUDE_TYPE enum now has a more specific enum value for this case:

Suggested change
return CSYNC_FILE_SILENTLY_EXCLUDED;
return CSYNC_FILE_LOCKED_SILENTLY_EXCLUDED;

}

if (csync_is_windows_reserved_word(bname)) {
return CSYNC_FILE_SILENTLY_EXCLUDED;
}
Expand Down Expand Up @@ -241,7 +250,7 @@
? _localPath
: leftIncludeLast(path, QLatin1Char('/'));
auto &excludeFilesLocalPath = _excludeFiles[basePath];
if (std::find(excludeFilesLocalPath.cbegin(), excludeFilesLocalPath.cend(), path) == excludeFilesLocalPath.cend()) {

Check warning on line 253 in src/csync/csync_exclude.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1uNDb1s0Fbzs2jIOw2&open=AZ1uNDb1s0Fbzs2jIOw2&pullRequest=9810
excludeFilesLocalPath.append(path);
}
}
Expand All @@ -261,7 +270,7 @@
Q_ASSERT(basePath.endsWith(QLatin1Char('/')));

const auto trimmedExpr = QStringView{expr}.trimmed();
if (trimmedExpr == QLatin1String("*")) {

Check warning on line 273 in src/csync/csync_exclude.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1uNDb1s0Fbzs2jIOw3&open=AZ1uNDb1s0Fbzs2jIOw3&pullRequest=9810
return;
}

Expand Down Expand Up @@ -451,7 +460,7 @@
// Check the bname part of the path to see whether the full
// regex should be run.
QStringView bnameStr(path);
int lastSlash = path.lastIndexOf(QLatin1Char('/'));

Check warning on line 463 in src/csync/csync_exclude.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=AZ1uNDb1s0Fbzs2jIOwx&open=AZ1uNDb1s0Fbzs2jIOwx&pullRequest=9810
if (lastSlash >= 0) {
bnameStr = bnameStr.mid(lastSlash + 1);
}
Expand Down Expand Up @@ -658,7 +667,7 @@
auto isWildcard = [](QChar c) { return c == QLatin1Char('*') || c == QLatin1Char('?'); };

// First, skip wildcards on the very right of the pattern
int i = pattern.size() - 1;

Check warning on line 670 in src/csync/csync_exclude.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=AZ1uNDb1s0Fbzs2jIOwy&open=AZ1uNDb1s0Fbzs2jIOwy&pullRequest=9810
while (i >= 0 && isWildcard(pattern[i]))
--i;

Expand Down
1 change: 1 addition & 0 deletions src/csync/csync_exclude.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef _CSYNC_EXCLUDE_H
#define _CSYNC_EXCLUDE_H

#include "ocsynclib.h"

Check failure on line 13 in src/csync/csync_exclude.h

View workflow job for this annotation

GitHub Actions / build

src/csync/csync_exclude.h:13:10 [clang-diagnostic-error]

'ocsynclib.h' file not found

#include "csync.h"

Expand All @@ -37,6 +37,7 @@
CSYNC_FILE_EXCLUDE_SERVER_BLACKLISTED,
CSYNC_FILE_EXCLUDE_LEADING_SPACE,
CSYNC_FILE_EXCLUDE_LEADING_AND_TRAILING_SPACE,
CSYNC_FILE_LOCKED_SILENTLY_EXCLUDED,

Check warning on line 40 in src/csync/csync_exclude.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=AZ2fvUKbgW1aIMTDWlLs&open=AZ2fvUKbgW1aIMTDWlLs&pullRequest=9810
};

class ExcludedFilesTest;
Expand Down
5 changes: 5 additions & 0 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2014 ownCloud GmbH
* 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 @@ -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=AZ2a_tiTy8hqXC4Khsig&open=AZ2a_tiTy8hqXC4Khsig&pullRequest=9810
{
qCDebug(lcFolder).nospace() << "retrieved root fileId=" << fileId;
_rootFileId = fileId;
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=AZ2a_tiTy8hqXC4Khsic&open=AZ2a_tiTy8hqXC4Khsic&pullRequest=9810
}

int Folder::downloadInfoCount()
Expand Down Expand Up @@ -709,10 +709,10 @@
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=AZ2a_tiTy8hqXC4Khsim&open=AZ2a_tiTy8hqXC4Khsim&pullRequest=9810
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=AZ2a_tiTy8hqXC4Khsin&open=AZ2a_tiTy8hqXC4Khsin&pullRequest=9810
spurious = false;
}
if (*pinState == PinState::OnlineOnly && record.isFile()) {
Expand Down Expand Up @@ -1001,6 +1001,11 @@
return true;
}

if (OCC::FileSystem::isFileLocked(path, OCC::FileSystem::LockMode::SharedRead)) {
qCDebug(lcFolder) << path << "is locked" << "skip syncing it";
return true;
}

#ifndef OWNCLOUD_TEST
if (isFileExcludedAbsolute(path) && !Utility::isConflictFile(path)) {
qCDebug(lcFolder) << "* Ignoring file" << path;
Expand Down Expand Up @@ -1631,7 +1636,7 @@
return;
}

QFileInfo excludeItemFileInfo(fullPath);

Check warning on line 1639 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=AZ2a_tiTy8hqXC4Khsix&open=AZ2a_tiTy8hqXC4Khsix&pullRequest=9810
const auto excludeItemFilePath = excludeItemFileInfo.filePath();
const auto message = FileSystem::isDir(fullPath)
? tr("The folder %1 was created but was excluded from synchronization previously. "
Expand Down Expand Up @@ -1660,13 +1665,13 @@

void Folder::slotHydrationStarts()
{
// // 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 1674 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=AZ2a_tiTy8hqXC4Khsi6&open=AZ2a_tiTy8hqXC4Khsi6&pullRequest=9810

// // Let everyone know we're syncing
// _syncResult.reset();
Expand All @@ -1683,7 +1688,7 @@
emit syncStateChange();
}

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

Check warning on line 1691 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=AZ2a_tiTy8hqXC4Khsiz&open=AZ2a_tiTy8hqXC4Khsiz&pullRequest=9810
{
_syncResult.setStatus(SyncResult::Error);
const auto errorMessageDetails = tr("Virtual file download failed with code \"%1\", status \"%2\" and error message \"%3\"")
Expand Down Expand Up @@ -1782,13 +1787,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 1790 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=AZ2a_tiTy8hqXC4Khsi4&open=AZ2a_tiTy8hqXC4Khsi4&pullRequest=9810
msg.arg(shortGuiLocalPath()), QMessageBox::NoButton);
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 1796 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=AZ2a_tiTy8hqXC4Khsi2&open=AZ2a_tiTy8hqXC4Khsi2&pullRequest=9810

Check warning on line 1796 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=AZ2a_tiTy8hqXC4Khsi5&open=AZ2a_tiTy8hqXC4Khsi5&pullRequest=9810
bool oldPaused = syncPaused();
setSyncPaused(true);
connect(msgBox, &QMessageBox::finished, this, [msgBox, keepBtn, callback, oldPaused, this] {
Expand Down
12 changes: 12 additions & 0 deletions src/libsync/discovery.cpp
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 Down Expand Up @@ -28,10 +28,10 @@

namespace
{
constexpr const char *editorNamesForDelayedUpload[] = {"PowerPDF"};

Check warning on line 31 in src/libsync/discovery.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use "std::array" or "std::vector" instead of a C-style array.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a_tmiy8hqXC4Khsi-&open=AZ2a_tmiy8hqXC4Khsi-&pullRequest=9810
constexpr const char *fileExtensionsToCheckIfOpenForSigning[] = {".pdf"};

Check warning on line 32 in src/libsync/discovery.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use "std::array" or "std::vector" instead of a C-style array.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a_tmiy8hqXC4Khsi_&open=AZ2a_tmiy8hqXC4Khsi_&pullRequest=9810
constexpr auto delayIntervalForSyncRetryForOpenedForSigningFilesSeconds = 60;
constexpr auto delayIntervalForSyncRetryForFilesExceedQuotaSeconds = 60;

Check warning on line 34 in src/libsync/discovery.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=AZ2a_tmiy8hqXC4KhsjC&open=AZ2a_tmiy8hqXC4KhsjC&pullRequest=9810
}

namespace OCC {
Expand Down Expand Up @@ -281,7 +281,7 @@
#if defined Q_OS_WINDOWS
if (hasLeadingOrTrailingSpaces && leadingAndTrailingSpacesFilesAllowed) {
#else
if (hasLeadingOrTrailingSpaces && (wasSyncedAlready || leadingAndTrailingSpacesFilesAllowed)) {

Check warning on line 284 in src/libsync/discovery.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a_tmiy8hqXC4KhsjF&open=AZ2a_tmiy8hqXC4KhsjF&pullRequest=9810
#endif
excluded = CSYNC_NOT_EXCLUDED;
}
Expand Down Expand Up @@ -354,6 +354,14 @@
}
}

if (excluded == CSYNC_NOT_EXCLUDED && OCC::FileSystem::isFileLocked(_discoveryData->_localDir + path, OCC::FileSystem::LockMode::SharedRead) &&
(!entries.dbEntry.isValid() || !entries.serverEntry.isValid() || entries.serverEntry.etag == entries.dbEntry._etag)) {
qCInfo(lcDisco) << _discoveryData->_localDir + path << "is locked" << "exluding it from sync";
excluded = CSYNC_FILE_LOCKED_SILENTLY_EXCLUDED;

emit _discoveryData->seenLockedFile(_discoveryData->_localDir + path);
}

if (excluded == CSYNC_NOT_EXCLUDED && !entries.localEntry.isSymLink) {
return false;
} else if (excluded == CSYNC_FILE_SILENTLY_EXCLUDED || excluded == CSYNC_FILE_EXCLUDE_AND_REMOVE) {
Expand Down Expand Up @@ -384,6 +392,9 @@
case CSYNC_FILE_EXCLUDE_AND_REMOVE:
qCFatal(lcDisco) << "These were handled earlier";
break;
case CSYNC_FILE_LOCKED_SILENTLY_EXCLUDED:
item->_errorString = tr("File is locked exluding it from sync.");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
item->_errorString = tr("File is locked exluding it from sync.");
item->_errorString = tr("File is locked by another application.");

break;
case CSYNC_FILE_EXCLUDE_LIST:
item->_errorString = tr("File is listed on the ignore list.");
break;
Expand Down Expand Up @@ -415,7 +426,7 @@
}
item->_status = SyncFileItem::FileNameInvalid;
break;
case CSYNC_FILE_EXCLUDE_TRAILING_SPACE:

Check warning on line 429 in src/libsync/discovery.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a_tmiy8hqXC4KhsjN&open=AZ2a_tmiy8hqXC4KhsjN&pullRequest=9810
item->_errorString = tr("Filename contains trailing spaces.");
item->_status = SyncFileItem::FileNameInvalid;
if (isLocal && !maybeRenameForWindowsCompatibility(_discoveryData->_localDir + item->_file, excluded)) {
Expand Down Expand Up @@ -457,7 +468,7 @@
case CSYNC_FILE_EXCLUDE_CANNOT_ENCODE:
item->_errorString = tr("The filename cannot be encoded on your file system.");
break;
case CSYNC_FILE_EXCLUDE_SERVER_BLACKLISTED:

Check warning on line 471 in src/libsync/discovery.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a_tmiy8hqXC4KhsjK&open=AZ2a_tmiy8hqXC4KhsjK&pullRequest=9810
const auto errorString = tr("The filename is blacklisted on the server.");
QString reasonString;
if (hasForbiddenFilename) {
Expand Down Expand Up @@ -683,7 +694,7 @@
_pendingAsyncJobs++;
_discoveryData->checkSelectiveSyncNewFolder(path._server,
serverEntry.remotePerm,
[=, this](bool result) {

Check failure on line 697 in src/libsync/discovery.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Explicitly capture the required scope variables.

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

Check warning on line 697 in src/libsync/discovery.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a_tmiy8hqXC4KhsjR&open=AZ2a_tmiy8hqXC4KhsjR&pullRequest=9810
--_pendingAsyncJobs;
if (!result) {
processFileAnalyzeLocalInfo(item, path, localEntry, serverEntry, dbEntry, _queryServer);
Expand Down Expand Up @@ -1050,7 +1061,7 @@
// we need to make a request to the server to know that the original file is deleted on the server
_pendingAsyncJobs++;
const auto job = new RequestEtagJob(_discoveryData->_account, _discoveryData->_remoteFolder + originalPath, this);
connect(job, &RequestEtagJob::finishedWithResult, this, [=, this](const HttpResult<QByteArray> &etag) mutable {

Check failure on line 1064 in src/libsync/discovery.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Explicitly capture the required scope variables.

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

Check failure on line 1064 in src/libsync/discovery.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Explicitly capture all local variables required in this lambda.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a_tmiy8hqXC4KhsjU&open=AZ2a_tmiy8hqXC4KhsjU&pullRequest=9810
_pendingAsyncJobs--;
QTimer::singleShot(0, _discoveryData, &DiscoveryPhase::scheduleMoreJobs);
if (etag || etag.error().code != 404 ||
Expand Down Expand Up @@ -1599,7 +1610,7 @@
const auto serverHasMountRootProperty = _discoveryData->_account->serverHasMountRootProperty();
const auto isExternalStorage = base._remotePerm.hasPermission(RemotePermissions::IsMounted) && base.isDirectory();
const auto movePerms = checkMovePermissions(base._remotePerm, originalPath, item->isDirectory());
if (!movePerms.sourceOk || !movePerms.destinationOk || (serverHasMountRootProperty && isExternalStorage) || isE2eeMoveOnlineOnlyItemWithCfApi) {

Check warning on line 1613 in src/libsync/discovery.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a_tmiy8hqXC4KhsjW&open=AZ2a_tmiy8hqXC4KhsjW&pullRequest=9810
qCInfo(lcDisco) << "Move without permission to rename base file, "
<< "source:" << movePerms.sourceOk
<< ", target:" << movePerms.destinationOk
Expand Down Expand Up @@ -1684,7 +1695,7 @@
if (base.isVirtualFile() && isVfsWithSuffix())
chopVirtualFileSuffix(serverOriginalPath);
auto job = new RequestEtagJob(_discoveryData->_account, serverOriginalPath, this);
connect(job, &RequestEtagJob::finishedWithResult, this, [=, this](const HttpResult<QByteArray> &etag) mutable {

Check failure on line 1698 in src/libsync/discovery.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Explicitly capture all local variables required in this lambda.

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


if (!etag || (etag.get() != base._etag && !item->isDirectory()) || _discoveryData->isRenamed(originalPath)
Expand Down Expand Up @@ -1730,7 +1741,7 @@
// If there's no content hash, use heuristics
if (serverEntry.checksumHeader.isEmpty()) {
// If the size or mtime is different, it's definitely a conflict.
bool isConflict = (serverEntry.size != localEntry.size) || (serverEntry.modtime != localEntry.modtime) || (dbEntry.isValid() && dbEntry._modtime != localEntry.modtime && serverEntry.modtime == localEntry.modtime);

Check warning on line 1744 in src/libsync/discovery.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

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

// It could be a conflict even if size and mtime match!
//
Expand Down Expand Up @@ -2107,7 +2118,7 @@
}

const auto isMatchingFileExtension = std::find_if(std::cbegin(fileExtensionsToCheckIfOpenForSigning), std::cend(fileExtensionsToCheckIfOpenForSigning),
[path](const auto &matchingExtension) {

Check warning on line 2121 in src/libsync/discovery.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Capture variables by reference, it is safe in this context.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a_tmiy8hqXC4Khsjl&open=AZ2a_tmiy8hqXC4Khsjl&pullRequest=9810
return path._local.endsWith(matchingExtension, Qt::CaseInsensitive);
}) != std::cend(fileExtensionsToCheckIfOpenForSigning);

Expand All @@ -2120,7 +2131,7 @@

for (const auto &detectedEditorName : editorsKeepingFileBusy) {
const auto isMatchingEditorFound = std::find_if(std::cbegin(editorNamesForDelayedUpload), std::cend(editorNamesForDelayedUpload),
[detectedEditorName](const auto &matchingEditorName) {

Check warning on line 2134 in src/libsync/discovery.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Capture variables by reference, it is safe in this context.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a_tmiy8hqXC4Khsjn&open=AZ2a_tmiy8hqXC4Khsjn&pullRequest=9810
return detectedEditorName.processName.startsWith(matchingEditorName, Qt::CaseInsensitive);
}) != std::cend(editorNamesForDelayedUpload);
if (isMatchingEditorFound) {
Expand Down Expand Up @@ -2354,7 +2365,7 @@
void ProcessDirectoryJob::startAsyncLocalQuery()
{
QString localPath = _discoveryData->_localDir + _currentFolder._local;
auto localJob = new DiscoverySingleLocalDirectoryJob(_discoveryData->_account, localPath, _discoveryData->_syncOptions._vfs.data(), _discoveryData->_fileSystemReliablePermissions);

Check warning on line 2368 in src/libsync/discovery.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "localJob" of type "class OCC::DiscoverySingleLocalDirectoryJob *" should be const-qualified.

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

_discoveryData->_currentlyActiveJobs++;
_pendingAsyncJobs++;
Expand Down Expand Up @@ -2443,19 +2454,20 @@
}

bool ProcessDirectoryJob::maybeRenameForWindowsCompatibility(const QString &absoluteFileName,
CSYNC_EXCLUDE_TYPE excludeReason)

Check warning on line 2457 in src/libsync/discovery.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "excludeReason" of type "enum CSYNC_EXCLUDE_TYPE" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a_tmiy8hqXC4Khsjt&open=AZ2a_tmiy8hqXC4Khsjt&pullRequest=9810
{
auto result = true;

const auto leadingAndTrailingSpacesFilesAllowed = !_discoveryData->_shouldEnforceWindowsFileNameCompatibility || _discoveryData->_leadingAndTrailingSpacesFilesAllowed.contains(absoluteFileName);
if (leadingAndTrailingSpacesFilesAllowed) {

Check warning on line 2462 in src/libsync/discovery.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a_tmiy8hqXC4Khsjq&open=AZ2a_tmiy8hqXC4Khsjq&pullRequest=9810
return result;
}

const auto fileInfo = QFileInfo{absoluteFileName};
switch (excludeReason)

Check failure on line 2467 in src/libsync/discovery.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a "default" case to this switch statement.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a_tmiy8hqXC4Khsjv&open=AZ2a_tmiy8hqXC4Khsjv&pullRequest=9810
{
case CSYNC_NOT_EXCLUDED:
case CSYNC_FILE_LOCKED_SILENTLY_EXCLUDED:
case CSYNC_FILE_EXCLUDE_CASE_CLASH_CONFLICT:
case CSYNC_FILE_EXCLUDE_AND_REMOVE:
case CSYNC_FILE_EXCLUDE_CANNOT_ENCODE:
Expand All @@ -2470,10 +2482,10 @@
break;
case CSYNC_FILE_EXCLUDE_LEADING_AND_TRAILING_SPACE:
case CSYNC_FILE_EXCLUDE_LEADING_SPACE:
case CSYNC_FILE_EXCLUDE_TRAILING_SPACE:

Check warning on line 2485 in src/libsync/discovery.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a_tmiy8hqXC4Khsju&open=AZ2a_tmiy8hqXC4Khsju&pullRequest=9810
{
const auto removeTrailingSpaces = [] (QString string) -> QString {
for (int n = string.size() - 1; n >= 0; -- n) {

Check warning on line 2488 in src/libsync/discovery.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=AZ2a_tmiy8hqXC4Khsi9&open=AZ2a_tmiy8hqXC4Khsi9&pullRequest=9810
if (!string.at(n).isSpace()) {
string.truncate(n + 1);
break;
Expand Down
3 changes: 3 additions & 0 deletions src/libsync/discoveryphase.h
Original file line number Diff line number Diff line change
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*/

Check warning on line 118 in src/libsync/discoveryphase.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=AZ2bDsJK1W-EvMDtBFsJ&open=AZ2bDsJK1W-EvMDtBFsJ&pullRequest=9810
const QSet<QString> &topLevelE2eeFolderPaths,
SyncFileItem::EncryptionStatus parentEncryptionStatus,
QObject *parent = nullptr);
Expand Down Expand Up @@ -345,6 +345,9 @@
void addErrorToGui(const OCC::SyncFileItem::Status status, const QString &errorMessage, const QString &subject, const OCC::ErrorCategory category);

void remnantReadOnlyFolderDiscovered(const OCC::SyncFileItemPtr &item);

/** Emitted when propagation would have problems with a locked file. */
void seenLockedFile(const QString &fileName);
private slots:
void slotItemDiscovered(const OCC::SyncFileItemPtr &item);
};
Expand Down
1 change: 0 additions & 1 deletion src/libsync/localdiscoverytracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
// For failures, we want to add the file to the list so the next sync
// will be able to retry it.
if (item->_status == SyncFileItem::Success
|| item->_status == SyncFileItem::FileIgnored
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why was this removed?

|| item->_status == SyncFileItem::Restoration
|| item->_status == SyncFileItem::Conflict
|| (item->_status == SyncFileItem::NoStatus
Expand All @@ -66,7 +65,7 @@
if (!item->_renameTarget.isEmpty() && _previousLocalDiscoveryPaths.erase(item->_renameTarget.toUtf8()))
qCDebug(lcLocalDiscoveryTracker) << "wiped successful item" << item->_renameTarget;
} else {
_localDiscoveryPaths.insert(item->_file.toUtf8());

Check warning on line 68 in src/libsync/localdiscoverytracker.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this use of "insert" with "emplace".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2rgulAnt0cq_Njpp9r&open=AZ2rgulAnt0cq_Njpp9r&pullRequest=9810
qCWarning(lcLocalDiscoveryTracker) << "inserted error item" << item->_file;
}
}
Expand Down
16 changes: 10 additions & 6 deletions src/libsync/propagateuploadng.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 "config.h"

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

View workflow job for this annotation

GitHub Actions / build

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

'config.h' file not found
#include "propagateupload.h"
#include "owncloudpropagator_p.h"
#include "networkjobs.h"
Expand Down Expand Up @@ -180,7 +180,7 @@
// we should remove the later chunks. Otherwise when we do dynamic chunk sizing, we may end up
// with corruptions if there are too many chunks, or if we abort and there are still stale chunks.
for (const auto &serverChunk : std::as_const(_serverChunks)) {
auto job = new DeleteJob(propagator()->account(), Utility::concatUrlPath(chunkUploadFolderUrl(), serverChunk.originalName), {}, this);

Check warning on line 183 in src/libsync/propagateuploadng.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Declaration shadows a local variable "job" in the outer scope.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2bDsNo1W-EvMDtBFsO&open=AZ2bDsNo1W-EvMDtBFsO&pullRequest=9810
QObject::connect(job, &DeleteJob::finishedSignal, this, &PropagateUploadFileNG::slotDeleteJobFinished);
_jobs.append(job);
job->start();
Expand Down Expand Up @@ -355,15 +355,19 @@
}

const auto fileName = _fileToUpload._path;
if (FileSystem::isFileLocked(fileName, FileSystem::LockMode::SharedRead)) {
// If the file is currently locked, we want to retry the sync
// when it becomes available again.
emit propagator()->seenLockedFile(fileName);

// Soft error because this is likely caused by the user modifying his files while syncing
abortWithError(SyncFileItem::FileLocked, tr("File is locked preventing syncing it", "Generic warning message when a locked file cannot be synced"));
return;
}
auto device = std::make_unique<UploadDevice>(fileName, _sent, _currentChunkSize, &propagator()->_bandwidthManager);
if (auto isLocked = FileSystem::isFileLocked(fileName, FileSystem::LockMode::SharedRead); isLocked || !device->open(QIODevice::ReadOnly)) {
if (!device->open(QIODevice::ReadOnly)) {
qCWarning(lcPropagateUploadNG) << "Could not prepare upload device: " << device->errorString();

// If the file is currently locked, we want to retry the sync
// when it becomes available again.
if (isLocked) {
emit propagator()->seenLockedFile(fileName);
}
// Soft error because this is likely caused by the user modifying his files while syncing
abortWithError(SyncFileItem::SoftError, device->errorString());
return;
Expand Down Expand Up @@ -536,7 +540,7 @@
}

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

Check warning on line 543 in src/libsync/propagateuploadng.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this "if" statement with the enclosing one.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2bDsNo1W-EvMDtBFsR&open=AZ2bDsNo1W-EvMDtBFsR&pullRequest=9810
_item->updateLockStateFromDbRecord(oldRecord);
}
}
Expand Down
15 changes: 9 additions & 6 deletions src/libsync/propagateuploadv1.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: 2016 ownCloud GmbH
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "config.h"

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

View workflow job for this annotation

GitHub Actions / build

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

'config.h' file not found
#include "propagateupload.h"
#include "owncloudpropagator_p.h"
#include "networkjobs.h"
Expand Down Expand Up @@ -74,7 +74,7 @@
startNextChunk();
}

void PropagateUploadFileV1::startNextChunk()

Check warning on line 77 in src/libsync/propagateuploadv1.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/propagateuploadv1.cpp:77:29 [readability-function-cognitive-complexity]

function 'startNextChunk' has cognitive complexity of 26 (threshold 25)
{
if (propagator()->_abortRequested)
return;
Expand Down Expand Up @@ -134,16 +134,19 @@
}

const QString fileName = _fileToUpload._path;
if (FileSystem::isFileLocked(fileName, FileSystem::LockMode::SharedRead)) {
emit propagator()->seenLockedFile(fileName);

// Soft error because this is likely caused by the user modifying his files while syncing
abortWithError(SyncFileItem::FileLocked, tr("File is locked preventing syncing it", "Generic warning message when a locked file cannot be synced"));
return;
}

auto device = std::make_unique<UploadDevice>(
fileName, chunkStart, currentChunkSize, &propagator()->_bandwidthManager);
if (auto isLocked = FileSystem::isFileLocked(fileName, FileSystem::LockMode::SharedRead); isLocked || !device->open(QIODevice::ReadOnly)) {
if (!device->open(QIODevice::ReadOnly)) {
qCWarning(lcPropagateUploadV1) << "Could not prepare upload device: " << device->errorString();

// If the file is currently locked, we want to retry the sync
// when it becomes available again.
if (isLocked) {
emit propagator()->seenLockedFile(fileName);
}
// Soft error because this is likely caused by the user modifying his files while syncing
abortWithError(SyncFileItem::SoftError, device->errorString());
return;
Expand Down Expand Up @@ -217,7 +220,7 @@
QNetworkReply::NetworkError err = job->reply()->error();
if (err != QNetworkReply::NoError) {
commonErrorHandling(job);
const auto exceptionParsed = getExceptionFromReply(job->reply());

Check warning on line 223 in src/libsync/propagateuploadv1.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=AZ1s17ML1MRvjmKtPry9&open=AZ1s17ML1MRvjmKtPry9&pullRequest=9810
_item->_errorExceptionName = exceptionParsed.first;
_item->_errorExceptionMessage = exceptionParsed.second;
return;
Expand Down Expand Up @@ -368,7 +371,7 @@
sender()->setProperty("byteWritten", sent);
if (_jobs.count() > 1) {
amount -= (_jobs.count() - 1) * chunkSize();
for (QObject *j : std::as_const(_jobs)) {

Check warning on line 374 in src/libsync/propagateuploadv1.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "j" of type "class QObject *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ1s17ML1MRvjmKtPrzA&open=AZ1s17ML1MRvjmKtPrzA&pullRequest=9810
amount += j->property("byteWritten").toULongLong();
}
} else {
Expand Down
1 change: 1 addition & 0 deletions src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@
qCWarning(lcEngine()) << "decrypt failed";
return;
}
// TODO: We need to rollback changes done to metadata in case we have an active lock, this needs to be implemented on the server first

Check warning on line 512 in src/libsync/syncengine.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=AZ2bDsGt1W-EvMDtBFrs&open=AZ2bDsGt1W-EvMDtBFrs&pullRequest=9810
const auto unlockJob = new OCC::UnlockEncryptFolderApiJob(_account, folderId, *folderToken, _journal, this);
unlockJob->setShouldRollbackMetadataChanges(true);
unlockJob->start();
Expand Down Expand Up @@ -708,6 +708,7 @@
connect(_discoveryPhase.get(), &DiscoveryPhase::silentlyExcluded,
_syncFileStatusTracker.data(), &SyncFileStatusTracker::slotAddSilentlyExcluded);
connect(_discoveryPhase.get(), &DiscoveryPhase::remnantReadOnlyFolderDiscovered, this, &SyncEngine::remnantReadOnlyFolderDiscovered);
connect(_discoveryPhase.get(), &DiscoveryPhase::seenLockedFile, this, &SyncEngine::seenLockedFile);

ProcessDirectoryJob *discoveryJob = nullptr;

Expand Down Expand Up @@ -1152,7 +1153,7 @@
return false;
}

bool SyncEngine::handleMassDeletion()

Check failure on line 1156 in src/libsync/syncengine.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2bDsGt1W-EvMDtBFr7&open=AZ2bDsGt1W-EvMDtBFr7&pullRequest=9810
{
const auto displayDialog = ConfigFile().promptDeleteFiles() && !_syncOptions.isCmd();
const auto allFilesDeleted = !_hasNoneFiles && _hasRemoveFile;
Expand Down Expand Up @@ -1185,7 +1186,7 @@
}
}

promptUserBeforePropagation([this, side](auto &&callback){

Check failure on line 1189 in src/libsync/syncengine.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

"std::forward" is never called on this forwarding reference argument.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2bDsGt1W-EvMDtBFr-&open=AZ2bDsGt1W-EvMDtBFr-&pullRequest=9810
emit aboutToRemoveAllFiles(side >= 0 ? SyncFileItem::Down : SyncFileItem::Up, callback);
});
return true;
Expand All @@ -1210,7 +1211,7 @@
slotAddTouchedFile(_localPath + oneFolder->_file);

if (oneFolder->_type == ItemType::ItemTypeDirectory) {
const auto deletionCallback = [this] (const QString &deleteItem, bool) {

Check warning on line 1214 in src/libsync/syncengine.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2bDsGt1W-EvMDtBFr_&open=AZ2bDsGt1W-EvMDtBFr_&pullRequest=9810
slotAddTouchedFile(deleteItem);
};

Expand Down Expand Up @@ -1239,7 +1240,7 @@
};

lambda(callback);
}

Check failure on line 1243 in src/libsync/syncengine.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Potential leak of memory pointed to by field 'value'

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2bDsGt1W-EvMDtBFsI&open=AZ2bDsGt1W-EvMDtBFsI&pullRequest=9810

void SyncEngine::slotAddTouchedFile(const QString &fn)
{
Expand Down Expand Up @@ -1277,7 +1278,7 @@
_leadingAndTrailingSpacesFilesAllowed.append(filePath);
}

void SyncEngine::setLocalDiscoveryEnforceWindowsFileNameCompatibility(bool value)

Check warning on line 1281 in src/libsync/syncengine.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=AZ2bDsGt1W-EvMDtBFsC&open=AZ2bDsGt1W-EvMDtBFsC&pullRequest=9810
{
_shouldEnforceWindowsFileNameCompatibility = value;
}
Expand Down Expand Up @@ -1314,14 +1315,14 @@
// This invariant is used in SyncEngine::shouldDiscoverLocally
QString prev;
auto it = _localDiscoveryPaths.begin();
while(it != _localDiscoveryPaths.end()) {
if (!prev.isNull() && it->startsWith(prev) && (prev.endsWith('/') || *it == prev || it->at(prev.size()) <= '/')) {
it = _localDiscoveryPaths.erase(it);
} else {
prev = *it;
++it;
}
}

Check warning on line 1325 in src/libsync/syncengine.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this loop with a "std::erase_if" call.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2bDsGt1W-EvMDtBFsE&open=AZ2bDsGt1W-EvMDtBFsE&pullRequest=9810
}

void SyncEngine::setSingleItemDiscoveryOptions(const SingleItemDiscoveryOptions &singleItemDiscoveryOptions)
Expand Down
2 changes: 1 addition & 1 deletion test/testlockedfiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* any purpose.
*/

#include <QtTest>

Check failure on line 11 in test/testlockedfiles.cpp

View workflow job for this annotation

GitHub Actions / build

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

'QtTest' file not found
#include "syncenginetestutils.h"
#include "lockwatcher.h"
#include <syncengine.h>
Expand Down Expand Up @@ -137,7 +137,7 @@

fakeFolder.syncEngine().setLocalDiscoveryOptions(LocalDiscoveryStyle::DatabaseAndFilesystem, tracker.localDiscoveryPaths());
tracker.startSyncPartialDiscovery();
QVERIFY(!fakeFolder.syncOnce());
QVERIFY(fakeFolder.syncOnce());

QVERIFY(seenLockedFiles.contains(fakeFolder.localPath() + "A/a1"));
QVERIFY(seenLockedFiles.size() == 1);
Expand Down
Loading