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
15 changes: 13 additions & 2 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 Down Expand Up @@ -84,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=AZ9HdTSaSdj6aD7GqUyu&open=AZ9HdTSaSdj6aD7GqUyu&pullRequest=10335
{
size_t len_filename = filename.size();

Expand Down Expand Up @@ -127,7 +127,7 @@
{
/* split up the path */
QStringView bname(path);
int lastSlash = bname.lastIndexOf(QLatin1Char('/'));

Check warning on line 130 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=AZ9HdTSaSdj6aD7GqUyr&open=AZ9HdTSaSdj6aD7GqUyr&pullRequest=10335

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9HdTSaSdj6aD7GqUyv&open=AZ9HdTSaSdj6aD7GqUyv&pullRequest=10335
if (lastSlash >= 0) {
bname = bname.mid(lastSlash + 1);
}
Expand Down Expand Up @@ -204,7 +204,7 @@

/* Do not sync desktop.ini files anywhere in the tree. */
const auto desktopIniFile = QStringLiteral("desktop.ini");
if (blen == static_cast<qsizetype>(desktopIniFile.length()) && bname.compare(desktopIniFile, Qt::CaseInsensitive) == 0) {

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this redundant cast.

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

Expand Down Expand Up @@ -250,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=AZ9HdTSaSdj6aD7GqUyx&open=AZ9HdTSaSdj6aD7GqUyx&pullRequest=10335
excludeFilesLocalPath.append(path);
}
}
Expand All @@ -270,11 +270,11 @@
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=AZ9HdTSaSdj6aD7GqUyy&open=AZ9HdTSaSdj6aD7GqUyy&pullRequest=10335
return;
}

auto key = basePath;

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Avoid this unnecessary copy by using a "const" reference.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9HdTSaSdj6aD7GqUyz&open=AZ9HdTSaSdj6aD7GqUyz&pullRequest=10335
_manualExcludes[key].append(expr);
_allExcludes[key].append(expr);
prepare(key);
Expand Down Expand Up @@ -302,14 +302,25 @@
QStringList patterns;
while (!file.atEnd()) {
QByteArray line = file.readLine().trimmed();
if (file.error()) {
// e.g. "Access to the cloud file is denied." when the exclude list is dehydrated on a VFS-enabled sync folder
qCWarning(lcCsyncExclude).nospace() << "failed to load exclude patterns from file, assume empty ignore list"
<< " fileName=" << file.fileName()
<< " error=" << file.error()
<< " errorString=" << file.errorString();
break;
}

if (line.startsWith("#!version")) {
if (!versionDirectiveKeepNextLine(line))
if (!versionDirectiveKeepNextLine(line)) {

Check warning on line 315 in src/csync/csync_exclude.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=AZ9HdTSaSdj6aD7GqUy1&open=AZ9HdTSaSdj6aD7GqUy1&pullRequest=10335
file.readLine();
}
}
if (line.isEmpty() || line.startsWith('#'))
if (line.isEmpty() || line.startsWith('#')) {
continue;
}
const auto patternStr = QString::fromUtf8(line);
if (QStringView{patternStr}.trimmed() == QLatin1StringView("*")) {

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9HdTSaSdj6aD7GqUy0&open=AZ9HdTSaSdj6aD7GqUy0&pullRequest=10335
continue;
}
csync_exclude_expand_escapes(line);
Expand Down Expand Up @@ -461,7 +472,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 475 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=AZ9HdTSaSdj6aD7GqUys&open=AZ9HdTSaSdj6aD7GqUys&pullRequest=10335
if (lastSlash >= 0) {
bnameStr = bnameStr.mid(lastSlash + 1);
}
Expand Down Expand Up @@ -668,7 +679,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 682 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=AZ9HdTSaSdj6aD7GqUyt&open=AZ9HdTSaSdj6aD7GqUyt&pullRequest=10335
while (i >= 0 && isWildcard(pattern[i]))
--i;

Expand Down
4 changes: 3 additions & 1 deletion src/libsync/vfs/cfapi/vfs_cfapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,9 @@ int VfsCfApi::finalizeNewPlaceholders(const QList<PlaceholderCreateInfo> &newEnt
folderRecord._isShared = entryInfo.parsedProperties.remotePerm.hasPermission(RemotePermissions::IsShared) || entryInfo.parsedProperties.sharedByMe;
folderRecord._sharedByMe = entryInfo.parsedProperties.sharedByMe;
folderRecord._lastShareStateFetchedTimestamp = QDateTime::currentMSecsSinceEpoch();
folderRecord._type = (entryInfo.parsedProperties.isDirectory ? ItemTypeVirtualDirectory : ItemTypeVirtualFile);
folderRecord._type =
(entryInfo.parsedProperties.isDirectory ? ItemTypeVirtualDirectory
: (FileSystem::isExcludeFile(entryInfo.fullPath) ? ItemTypeVirtualFileDownload : ItemTypeVirtualFile));
folderRecord._etag = entryInfo.parsedProperties.etag;
folderRecord._e2eEncryptionStatus = static_cast<SyncJournalFileRecord::EncryptionStatus>(entryInfo.parsedProperties.isE2eEncrypted() ? SyncFileItem::EncryptionStatus::EncryptedMigratedV2_0 : SyncFileItem::EncryptionStatus::NotEncrypted);
folderRecord._lockstate._locked = (entryInfo.parsedProperties.locked == SyncFileItemEnums::LockStatus::LockedItem);
Expand Down
Loading