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
29 changes: 1 addition & 28 deletions src/gui/folderman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
return _folderMap;
}

void FolderMan::unloadFolder(Folder *f)

Check warning on line 116 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=AZ752_SC6OA4qYu6YpdN&open=AZ752_SC6OA4qYu6YpdN&pullRequest=10244
{
if (!f) {
return;
Expand Down Expand Up @@ -232,7 +232,7 @@
folder->processSwitchedToVirtualFiles();
}

return _folderMap.size();

Check warning on line 235 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=AZ752_SC6OA4qYu6YpdK&open=AZ752_SC6OA4qYu6YpdK&pullRequest=10244
}

void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account, const QStringList &ignoreKeys, bool backwardsCompatible, bool foldersWithPlaceholders)
Expand Down Expand Up @@ -607,7 +607,7 @@
return;
}

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

Check warning on line 610 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=AZ752_SC6OA4qYu6YpdS&open=AZ752_SC6OA4qYu6YpdS&pullRequest=10244
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 @@ -687,7 +687,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 690 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=AZ752_SC6OA4qYu6YpdQ&open=AZ752_SC6OA4qYu6YpdQ&pullRequest=10244
folder->migrateBlackListPath(legacyFolder);
}
settings.remove(QLatin1String("blackList"));
Expand Down Expand Up @@ -1051,7 +1051,7 @@
void FolderMan::slotStartScheduledFolderSync()
{
if (isAnySyncRunning()) {
for (auto f : std::as_const(_folderMap)) {

Check warning on line 1054 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=AZ752_SC6OA4qYu6YpdU&open=AZ752_SC6OA4qYu6YpdU&pullRequest=10244
if (f->isSyncRunning())
qCInfo(lcFolderMan) << "Currently folder " << f->remoteUrl().toString() << " is running, wait for finish!";
}
Expand Down Expand Up @@ -1490,10 +1490,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 1496 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=AZ752_SC6OA4qYu6YpdY&open=AZ752_SC6OA4qYu6YpdY&pullRequest=10244

return it != folders.cend() ? *it : nullptr;
}
Expand Down Expand Up @@ -1717,27 +1717,7 @@
SyncJournalFileRecord rec;
if (folder->journalDb()->getFileRecord(filePathRelative, &rec)
&& rec.isValid() && rec.isE2eEncrypted()) {

if (_removeE2eeShareJob) {
_removeE2eeShareJob->deleteLater();
}

_removeE2eeShareJob = new UpdateE2eeFolderUsersMetadataJob(folder->accountState()->account(),
folder->journalDb(),
folder->remotePath(),
UpdateE2eeFolderUsersMetadataJob::Remove,
folder->remotePathTrailingSlash() + filePathRelative,
folder->accountState()->account()->davUser());
_removeE2eeShareJob->setParent(this);
_removeE2eeShareJob->start(true);
connect(_removeE2eeShareJob, &UpdateE2eeFolderUsersMetadataJob::finished, this, [localFileNoTrailingSlash, this](int code, const QString &message) {
if (code != 200) {
qCWarning(lcFolderMan) << "Could not remove share from E2EE folder's metadata!" << code << message;
return;
}
slotLeaveShare(localFileNoTrailingSlash, _removeE2eeShareJob->folderToken());
});

qCWarning(lcFolderMan) << "You cannot remove yourself from an encrypted share";
return;
}
slotLeaveShare(localFileNoTrailingSlash);
Expand All @@ -1757,23 +1737,16 @@
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 1740 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=AZ752_SC6OA4qYu6Ypde&open=AZ752_SC6OA4qYu6Ypde&pullRequest=10244
qCDebug(lcFolderMan) << "slotLeaveShare callback statusCode" << statusCode;
Q_UNUSED(statusCode);
if (_removeE2eeShareJob) {
_removeE2eeShareJob->unlockFolder(EncryptedFolderMetadataHandler::UnlockFolderWithResult::Success);
connect(_removeE2eeShareJob.data(), &UpdateE2eeFolderUsersMetadataJob::folderUnlocked, this, [this, folder] {
scheduleFolder(folder);
});
return;
}
scheduleFolder(folder);
});
leaveShareJob->start();
}

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

Check warning on line 1749 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=AZ752_SC6OA4qYu6Ypdg&open=AZ752_SC6OA4qYu6Ypdg&pullRequest=10244
bool *unresolvedConflicts,
ProgressInfo **const overallProgressInfo)
{
Expand Down Expand Up @@ -1877,7 +1850,7 @@
}
}

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

Check warning on line 1853 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=AZ752_SC6OA4qYu6Ypdm&open=AZ752_SC6OA4qYu6Ypdm&pullRequest=10244
{
QString folderMessage;
switch (syncStatus) {
Expand All @@ -1896,7 +1869,7 @@
if (progress->totalSize() == 0) {
qint64 currentFile = progress->currentFile();
qint64 totalFileCount = qMax(progress->totalFiles(), currentFile);
if (progress->trustEta()) {

Check failure on line 1872 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=AZ752_SC6OA4qYu6Ypdj&open=AZ752_SC6OA4qYu6Ypdj&pullRequest=10244
if (estimatedEta == 0) {
folderMessage = tr("Syncing %1 of %2 (A few seconds left)").arg(currentFile).arg(totalFileCount);
} else {
Expand Down
2 changes: 0 additions & 2 deletions src/gui/folderman.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,6 @@ private slots:
NavigationPaneHelper _navigationPaneHelper;
#endif

QPointer<UpdateE2eeFolderUsersMetadataJob> _removeE2eeShareJob;

bool _appRestartRequired = false;

static FolderMan *_instance;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/socketapi/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@
job->start();
}

void SocketApi::command_FILE_ACTIONS(const QString &localFile, SocketListener *listener)

Check warning on line 770 in src/gui/socketapi/socketapi.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 "listener" is "class OCC::SocketListener *".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ752_NU6OA4qYu6Ypc5&open=AZ752_NU6OA4qYu6Ypc5&pullRequest=10244
{
Q_UNUSED(listener);

Expand Down Expand Up @@ -1166,10 +1166,10 @@

auto capabilities = fileData.folder->accountState()->account()->capabilities();
auto theme = Theme::instance();
if (!capabilities.shareAPI() || !(theme->userGroupSharing() || (theme->linkSharing() && capabilities.sharePublicLink())))

Check warning on line 1169 in src/gui/socketapi/socketapi.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

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

if (record._isShared && !record._sharedByMe) {
if (record._isShared && !record._sharedByMe && itemEncryptionFlag == SharingContextItemEncryptedFlag::NotEncryptedItem) {
listener->sendMessage(QLatin1String("MENU_ITEM:LEAVESHARE") + flagString + tr("Leave this share"));
}

Expand All @@ -1190,7 +1190,7 @@
//listener->sendMessage(QLatin1String("MENU_ITEM:EMAIL_PRIVATE_LINK") + flagString + tr("Send private link by email …"));
}

void SocketApi::sendFileActionsContextMenuOptions(const FileData &fileData, SocketListener *listener)

Check warning on line 1193 in src/gui/socketapi/socketapi.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=AZ752_NU6OA4qYu6YpdC&open=AZ752_NU6OA4qYu6YpdC&pullRequest=10244
{
const auto record = fileData.journalRecord();
const auto isOnTheServer = record.isValid();
Expand Down Expand Up @@ -1289,7 +1289,7 @@

data.folderRelativePath = data.localPath.mid(data.folder->cleanPath().length() + 1);
data.serverRelativePath = QDir(data.folder->remotePath()).filePath(data.folderRelativePath);
QString virtualFileExt = QStringLiteral(APPLICATION_DOTVIRTUALFILE_SUFFIX);

Check warning on line 1292 in src/gui/socketapi/socketapi.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=AZ752_NU6OA4qYu6YpdH&open=AZ752_NU6OA4qYu6YpdH&pullRequest=10244
if (data.serverRelativePath.endsWith(virtualFileExt)) {
data.serverRelativePath.chop(virtualFileExt.size());
}
Expand Down
10 changes: 8 additions & 2 deletions src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
constexpr const char *editorNamesForDelayedUpload[] = {"PowerPDF"};
constexpr const char *fileExtensionsToCheckIfOpenForSigning[] = {".pdf"};
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=AZ752_gk6OA4qYu6Ypeq&open=AZ752_gk6OA4qYu6Ypeq&pullRequest=10244
}

namespace OCC {
Expand Down Expand Up @@ -252,7 +252,7 @@
QTimer::singleShot(0, _discoveryData, &DiscoveryPhase::scheduleMoreJobs);
}

bool ProcessDirectoryJob::handleExcluded(const QString &path, const Entries &entries, const std::map<QString, Entries> &allEntries, const bool isHidden, const bool isBlacklisted)

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ752_gk6OA4qYu6Ypeu&open=AZ752_gk6OA4qYu6Ypeu&pullRequest=10244
{
const auto isDirectory = entries.localEntry.isDirectory || entries.serverEntry.isDirectory;

Expand Down Expand Up @@ -318,15 +318,15 @@

auto forbiddenCharMatch = QString{};
const auto containsForbiddenCharacters =
std::any_of(forbiddenChars.cbegin(),
forbiddenChars.cend(),
[&localName, &forbiddenCharMatch](const QString &charPattern) {
if (localName.contains(charPattern)) {
forbiddenCharMatch = charPattern;
return true;
}
return false;
});

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

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

if (excluded == CSYNC_NOT_EXCLUDED && !localName.isEmpty()
&& !wasSyncedAlready
Expand Down Expand Up @@ -425,7 +425,7 @@
}
item->_status = SyncFileItem::FileNameInvalid;
break;
case CSYNC_FILE_EXCLUDE_TRAILING_SPACE:

Check warning on line 428 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=AZ752_gk6OA4qYu6Ype1&open=AZ752_gk6OA4qYu6Ype1&pullRequest=10244
item->_errorString = tr("Filename contains trailing spaces.");
item->_status = SyncFileItem::FileNameInvalid;
if (isLocal && !maybeRenameForWindowsCompatibility(_discoveryData->_localDir + item->_file, excluded)) {
Expand Down Expand Up @@ -693,7 +693,7 @@
_pendingAsyncJobs++;
_discoveryData->checkSelectiveSyncNewFolder(path._server,
serverEntry.remotePerm,
[=, this](bool result) {

Check failure on line 696 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=AZ752_gk6OA4qYu6Ype3&open=AZ752_gk6OA4qYu6Ype3&pullRequest=10244
--_pendingAsyncJobs;
if (!result) {
processFileAnalyzeLocalInfo(item, path, localEntry, serverEntry, dbEntry, _queryServer);
Expand Down Expand Up @@ -753,17 +753,23 @@
if (item->_e2eEncryptionStatusRemote != SyncFileItem::EncryptionStatus::NotEncrypted) {
Q_ASSERT(item->_e2eEncryptionStatus != SyncFileItem::EncryptionStatus::NotEncrypted);
}
item->_encryptedFileName = [=, this] {

Check warning on line 756 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=AZ752_gk6OA4qYu6Ype6&open=AZ752_gk6OA4qYu6Ype6&pullRequest=10244
auto result = QString{};

if (item->_e2eEncryptionStatus == SyncFileItem::EncryptionStatus::NotEncrypted) {
return result;
}
if (serverEntry.e2eMangledName.isEmpty()) {
return QString();
return result;
}

Q_ASSERT(_discoveryData->_remoteFolder.startsWith('/'));
Q_ASSERT(_discoveryData->_remoteFolder.endsWith('/'));

const auto rootPath = _discoveryData->_remoteFolder.mid(1);
Q_ASSERT(serverEntry.e2eMangledName.startsWith(rootPath));
return serverEntry.e2eMangledName.mid(rootPath.length());
result = serverEntry.e2eMangledName.mid(rootPath.length());
return result;
}();
item->_locked = serverEntry.locked;
item->_lockOwnerDisplayName = serverEntry.lockOwnerDisplayName;
Expand Down Expand Up @@ -1609,7 +1615,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 1618 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=AZ752_gk6OA4qYu6Ype-&open=AZ752_gk6OA4qYu6Ype-&pullRequest=10244
qCInfo(lcDisco) << "Move without permission to rename base file, "
<< "source:" << movePerms.sourceOk
<< ", target:" << movePerms.destinationOk
Expand Down Expand Up @@ -1650,7 +1656,7 @@
return;
}

auto wasDeletedOnClient = _discoveryData->findAndCancelDeletedJob(originalPath);

Check warning on line 1659 in src/libsync/discovery.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=AZ752_gk6OA4qYu6YpfF&open=AZ752_gk6OA4qYu6YpfF&pullRequest=10244

auto processRename = [item, originalPath, base, this](PathTuple &path) {
auto adjustedOriginalPath = _discoveryData->adjustRenamedPath(originalPath, SyncFileItem::Down);
Expand Down Expand Up @@ -1694,7 +1700,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 1703 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=AZ752_gk6OA4qYu6YpfG&open=AZ752_gk6OA4qYu6YpfG&pullRequest=10244


if (!etag || (etag.get() != base._etag && !item->isDirectory()) || _discoveryData->isRenamed(originalPath)
Expand Down Expand Up @@ -1863,7 +1869,7 @@
if (_discoveryData->_syncOptions._vfs && _discoveryData->_syncOptions._vfs->mode() != OCC::Vfs::Off &&
(item->_type == CSyncEnums::ItemTypeFile || item->_type == CSyncEnums::ItemTypeDirectory) &&
item->_instruction == CSyncEnums::CSYNC_INSTRUCTION_NONE &&
FileSystem::isLnkFile((_discoveryData->_localDir + path._local)) &&

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove these redundant parentheses.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ752_gk6OA4qYu6YpfK&open=AZ752_gk6OA4qYu6YpfK&pullRequest=10244
!_discoveryData->_syncOptions._vfs->isPlaceHolderInSync(_discoveryData->_localDir + path._local)) {
item->_instruction = CSyncEnums::CSYNC_INSTRUCTION_SYNC;
item->_direction = SyncFileItem::Down;
Expand Down Expand Up @@ -2116,10 +2122,10 @@
return matchingEditorsKeepingFileBusy;
}

const auto isMatchingFileExtension = std::find_if(std::cbegin(fileExtensionsToCheckIfOpenForSigning), std::cend(fileExtensionsToCheckIfOpenForSigning),
[path](const auto &matchingExtension) {
return path._local.endsWith(matchingExtension, Qt::CaseInsensitive);
}) != std::cend(fileExtensionsToCheckIfOpenForSigning);

Check warning on line 2128 in src/libsync/discovery.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=AZ752_gk6OA4qYu6YpfM&open=AZ752_gk6OA4qYu6YpfM&pullRequest=10244

if (!isMatchingFileExtension) {
return matchingEditorsKeepingFileBusy;
Expand Down Expand Up @@ -2364,7 +2370,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 2373 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=AZ752_gk6OA4qYu6YpfR&open=AZ752_gk6OA4qYu6YpfR&pullRequest=10244

_discoveryData->_currentlyActiveJobs++;
_pendingAsyncJobs++;
Expand Down Expand Up @@ -2452,7 +2458,7 @@
}
}

bool ProcessDirectoryJob::maybeRenameForWindowsCompatibility(const QString &absoluteFileName,

Check warning on line 2461 in src/libsync/discovery.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=AZ752_gk6OA4qYu6YpfU&open=AZ752_gk6OA4qYu6YpfU&pullRequest=10244
CSYNC_EXCLUDE_TYPE excludeReason)
{
auto result = true;
Expand All @@ -2463,7 +2469,7 @@
}

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

Check failure on line 2472 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=AZ752_gk6OA4qYu6YpfX&open=AZ752_gk6OA4qYu6YpfX&pullRequest=10244
{
case CSYNC_NOT_EXCLUDED:
case CSYNC_FILE_LOCKED_SILENTLY_EXCLUDED:
Expand All @@ -2481,10 +2487,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 2490 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=AZ752_gk6OA4qYu6YpfW&open=AZ752_gk6OA4qYu6YpfW&pullRequest=10244
{
const auto removeTrailingSpaces = [] (QString string) -> QString {
for (int n = string.size() - 1; n >= 0; -- n) {

Check warning on line 2493 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=AZ752_gk6OA4qYu6Ypel&open=AZ752_gk6OA4qYu6Ypel&pullRequest=10244
if (!string.at(n).isSpace()) {
string.truncate(n + 1);
break;
Expand Down
10 changes: 8 additions & 2 deletions src/libsync/discoveryphase.cpp
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 @@ -76,7 +76,7 @@
connect(propfindJob, &PropfindJob::finishedWithError, this, [=] {
return completionCallback(false);
});
connect(propfindJob, &PropfindJob::result, this, [=, this](const QVariantMap &values) {

Check failure on line 79 in src/libsync/discoveryphase.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=AZ752_T06OA4qYu6Ypd6&open=AZ752_T06OA4qYu6Ypd6&pullRequest=10244
const auto result = values.value(QLatin1String("size")).toLongLong();
const auto limit = _syncOptions._newBigFolderSizeLimit;
qCDebug(lcDiscovery) << "Folder size check complete for" << path << "result:" << result << "limit:" << limit;
Expand Down Expand Up @@ -370,7 +370,7 @@
QVector<LocalInfo> results;
while (true) {
errno = 0;
auto dirent = csync_vio_local_readdir(dh, _vfs, _fileSystemReliablePermissions);

Check warning on line 373 in src/libsync/discoveryphase.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "dirent" of type "class std::unique_ptr<struct csync_file_stat_s>" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ752_T06OA4qYu6YpeB&open=AZ752_T06OA4qYu6YpeB&pullRequest=10244
if (!dirent)
break;
if (dirent->type == ItemTypeSkip)
Expand Down Expand Up @@ -587,7 +587,7 @@
deleteLater();
}

void DiscoverySingleDirectoryJob::lsJobFinishedWithErrorSlot(QNetworkReply *reply)

Check warning on line 590 in src/libsync/discoveryphase.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 "reply" is "class QNetworkReply *".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ752_T06OA4qYu6YpeI&open=AZ752_T06OA4qYu6YpeI&pullRequest=10244
{
const auto contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
const auto invalidContentType = !contentType.contains("application/xml; charset=utf-8") &&
Expand Down Expand Up @@ -660,7 +660,7 @@
case FolderMetadata::MetadataVersion::Version1_2:
break;
case FolderMetadata::MetadataVersion::Version2_0:
case FolderMetadata::MetadataVersion::Version2_1:

Check warning on line 663 in src/libsync/discoveryphase.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ752_T06OA4qYu6YpeM&open=AZ752_T06OA4qYu6YpeM&pullRequest=10244
if (job->signature().isEmpty()) {
qCDebug(lcDiscovery) << "Initial signature is empty.";
_account->reportClientStatus(OCC::ClientStatusReportingStatus::E2EeError_GeneralError);
Expand All @@ -671,11 +671,17 @@
break;
}

const auto rootEncryptedFolderInfo = RootEncryptedFolderInfo{Utility::fullRemotePathToRemoteSyncRootRelative(topLevelFolderPath, _remoteRootFolderPath)};

const auto folderType = _topLevelE2eeFolderPaths.contains(_subPath) ? FolderMetadata::FolderType::Root : FolderMetadata::FolderType::Nested;
Q_ASSERT((folderType == FolderMetadata::FolderType::Root) == (rootEncryptedFolderInfo.path == QStringLiteral("/")));

const auto e2EeFolderMetadata = new FolderMetadata(_account,
_remoteRootFolderPath,
jsonMetadata,
RootEncryptedFolderInfo(Utility::fullRemotePathToRemoteSyncRootRelative(topLevelFolderPath, _remoteRootFolderPath)),
job->signature());
rootEncryptedFolderInfo,
job->signature(),
folderType);
connect(e2EeFolderMetadata, &FolderMetadata::setupComplete, this, [this, e2EeFolderMetadata] {
e2EeFolderMetadata->deleteLater();
if (!e2EeFolderMetadata->isValid()) {
Expand All @@ -694,9 +700,9 @@
const auto encryptedFiles = e2EeFolderMetadata->files();

const auto findEncryptedFile = [=](const QString &name) {
const auto it = std::find_if(std::cbegin(encryptedFiles), std::cend(encryptedFiles), [=](const FolderMetadata::EncryptedFile &file) {
return file.encryptedFilename == name;
});

Check warning on line 705 in src/libsync/discoveryphase.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=AZ752_T06OA4qYu6YpeQ&open=AZ752_T06OA4qYu6YpeQ&pullRequest=10244
if (it == std::cend(encryptedFiles)) {
return Optional<FolderMetadata::EncryptedFile>();
} else {
Expand Down
9 changes: 8 additions & 1 deletion src/libsync/encryptedfoldermetadatahandler.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-2.0-or-later
Expand All @@ -14,6 +14,8 @@
#include <QLoggingCategory>
#include <QNetworkReply>

using namespace Qt::StringLiterals;

namespace OCC {

Q_LOGGING_CATEGORY(lcFetchAndUploadE2eeFolderMetadataJob, "nextcloud.sync.propagator.encryptedfoldermetadatahandler", QtInfoMsg)
Expand Down Expand Up @@ -99,7 +101,7 @@

void EncryptedFolderMetadataHandler::startFetchMetadata()
{
const auto job = new GetMetadataApiJob(_account, _folderId);

Check failure on line 104 in src/libsync/encryptedfoldermetadatahandler.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=AZ752_cW6OA4qYu6YpeW&open=AZ752_cW6OA4qYu6YpeW&pullRequest=10244
connect(job, &GetMetadataApiJob::jsonReceived, this, &EncryptedFolderMetadataHandler::slotMetadataReceived);
connect(job, &GetMetadataApiJob::error, this, &EncryptedFolderMetadataHandler::slotMetadataReceivedError);
job->start();
Expand Down Expand Up @@ -148,7 +150,7 @@
startFetchMetadata();
}

void EncryptedFolderMetadataHandler::slotFolderEncryptedIdError(QNetworkReply *reply)

Check warning on line 153 in src/libsync/encryptedfoldermetadatahandler.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "reply" of type "class QNetworkReply *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ752_cW6OA4qYu6Ypea&open=AZ752_cW6OA4qYu6Ypea&pullRequest=10244
{
Q_ASSERT(reply);
qCWarning(lcFetchAndUploadE2eeFolderMetadataJob) << "Error retrieving the Id of the encrypted folder.";
Expand Down Expand Up @@ -183,7 +185,12 @@

const auto rawMetadata = statusCode == 404
? QByteArray{} : json.toJson(QJsonDocument::Compact);
const auto metadata(QSharedPointer<FolderMetadata>::create(_account, _remoteFolderRoot, rawMetadata, _rootEncryptedFolderInfo, job->signature()));
const auto metadata(QSharedPointer<FolderMetadata>::create(_account,
_remoteFolderRoot,
rawMetadata,
_rootEncryptedFolderInfo,
job->signature(),
(_rootEncryptedFolderInfo.path == u"/"_s ? FolderMetadata::FolderType::Root : FolderMetadata::FolderType::Nested)));
connect(metadata.data(), &FolderMetadata::setupComplete, this, [this, metadata] {
if (!metadata->isValid()) {
qCWarning(lcFetchAndUploadE2eeFolderMetadataJob) << "Error parsing or decrypting metadata for folder" << _folderFullRemotePath;
Expand All @@ -195,7 +202,7 @@
});
}

void EncryptedFolderMetadataHandler::slotMetadataReceivedError(const QByteArray &folderId, int httpReturnCode)

Check warning on line 205 in src/libsync/encryptedfoldermetadatahandler.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ752_cW6OA4qYu6Ypec&open=AZ752_cW6OA4qYu6Ypec&pullRequest=10244
{
Q_UNUSED(folderId);
if (_fetchMode == FetchMode::AllowEmptyMetadata) {
Expand Down
9 changes: 7 additions & 2 deletions src/libsync/encryptfolderjob.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-2.0-or-later
Expand All @@ -10,6 +10,8 @@
#include "foldermetadata.h"
#include <QLoggingCategory>

using namespace Qt::StringLiterals;

namespace OCC {

Q_LOGGING_CATEGORY(lcEncryptFolderJob, "nextcloud.sync.propagator.encryptfolder", QtInfoMsg)
Expand Down Expand Up @@ -103,12 +105,15 @@
return;
}

const auto rootEncryptedFolderInfo = RootEncryptedFolderInfo{RootEncryptedFolderInfo::createRootPath(currentPathRelative, rec.path())};

const auto emptyMetadata(QSharedPointer<FolderMetadata>::create(
_account,
_remoteSyncRootPath,
QByteArray{},
RootEncryptedFolderInfo(RootEncryptedFolderInfo::createRootPath(currentPathRelative, rec.path())),
QByteArray{}));
rootEncryptedFolderInfo,
QByteArray{},
rootEncryptedFolderInfo.path == u"/"_s ? FolderMetadata::FolderType::Root : FolderMetadata::FolderType::Nested));

connect(emptyMetadata.data(), &FolderMetadata::setupComplete, this, [this, emptyMetadata] {
const auto encryptedMetadata = !emptyMetadata->isValid() ? QByteArray{} : emptyMetadata->encryptedMetadata();
Expand Down
7 changes: 6 additions & 1 deletion src/libsync/foldermetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
return mimetype.isEmpty() || mimetype == QByteArrayLiteral("inode/directory") || mimetype == QByteArrayLiteral("httpd/unix-directory");
}

FolderMetadata::FolderMetadata(AccountPtr account, const QString &remoteFolderRoot, FolderType folderType) :

Check warning on line 57 in src/libsync/foldermetadata.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ752_i26OA4qYu6Ypff&open=AZ752_i26OA4qYu6Ypff&pullRequest=10244
_account(account),
_remoteFolderRoot(Utility::noLeadingSlashPath(Utility::noTrailingSlashPath(remoteFolderRoot))),
_isRootEncryptedFolder(folderType == FolderType::Root)
Expand All @@ -68,17 +68,19 @@
const QByteArray &metadata,
const RootEncryptedFolderInfo &rootEncryptedFolderInfo,
const QByteArray &signature,
FolderType folderType,
QObject *parent)
: QObject(parent)
, _account(account)
, _remoteFolderRoot(Utility::noLeadingSlashPath(Utility::noTrailingSlashPath(remoteFolderRoot)))
, _initialMetadata(metadata)
, _isRootEncryptedFolder(rootEncryptedFolderInfo.path == QStringLiteral("/"))
, _isRootEncryptedFolder(folderType == FolderType::Root)
, _binaryMetadataKeyForEncryption(rootEncryptedFolderInfo.binaryKeyForEncryption)
, _binaryMetadataKeyForDecryption(rootEncryptedFolderInfo.binaryKeyForDecryption)
, _keyChecksums(rootEncryptedFolderInfo.keyChecksums)
, _initialSignature(signature)
{
Q_ASSERT(_isRootEncryptedFolder == (rootEncryptedFolderInfo.path == QStringLiteral("/")));
Q_ASSERT(!_remoteFolderRoot.isEmpty());
_existingMetadataVersion = setupVersionFromExistingMetadata(metadata);

Expand Down Expand Up @@ -131,6 +133,9 @@
const auto folderUsers = metaDataDoc[usersKey].toArray();

const auto isUsersArrayValid = (!_isRootEncryptedFolder && folderUsers.isEmpty()) || (_isRootEncryptedFolder && !folderUsers.isEmpty());
if (!isUsersArrayValid) {
qCCritical(lcCseMetadata()) << (_isRootEncryptedFolder ? "is root encrypted folder" : "is child encrypted folder") << folderUsers;
}
Q_ASSERT(isUsersArrayValid);

if (!isUsersArrayValid) {
Expand Down Expand Up @@ -239,7 +244,7 @@

const auto counterVariantFromJson = cipherTextObj.value(counterKey).toVariant();
if (counterVariantFromJson.isValid() && counterVariantFromJson.canConvert<quint64>()) {
// TODO: We need to check counter: new counter must be greater than locally stored counter

Check warning on line 247 in src/libsync/foldermetadata.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=AZ752_i26OA4qYu6Ypfe&open=AZ752_i26OA4qYu6Ypfe&pullRequest=10244
// What does that mean? We store the counter in metadata, should we now store it in local database as we do for all file records in SyncJournal?
// What if metadata was not updated for a while? The counter will then not be greater than locally stored (in SyncJournal DB?)
_counter = counterVariantFromJson.value<quint64>();
Expand Down Expand Up @@ -378,7 +383,7 @@
_isMetadataValid = true;
}

FolderMetadata::MetadataVersion FolderMetadata::setupVersionFromExistingMetadata(const QByteArray &metadata)

Check warning on line 386 in src/libsync/foldermetadata.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=AZ752_i26OA4qYu6Ypfr&open=AZ752_i26OA4qYu6Ypfr&pullRequest=10244
{
auto resultVersion = FolderMetadata::MetadataVersion{};
const auto &doc = QJsonDocument::fromJson(metadata);
Expand Down Expand Up @@ -484,9 +489,9 @@
auto mnemonic = _account->e2e()->getMnemonic();
hashAlgorithm.addData(mnemonic.remove(' ').toUtf8());
auto sortedFiles = _files;
std::sort(sortedFiles.begin(), sortedFiles.end(), [](const auto &first, const auto &second) {
return first.encryptedFilename < second.encryptedFilename;
});

Check warning on line 494 in src/libsync/foldermetadata.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ752_i26OA4qYu6Ypft&open=AZ752_i26OA4qYu6Ypft&pullRequest=10244
for (const auto &singleFile : sortedFiles) {
hashAlgorithm.addData(singleFile.encryptedFilename.toUtf8());
}
Expand Down Expand Up @@ -528,7 +533,7 @@
return file;
}

QJsonObject FolderMetadata::convertFileToJsonObject(const EncryptedFile *encryptedFile) const

Check warning on line 536 in src/libsync/foldermetadata.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "encryptedFile" of type "const struct OCC::FolderMetadata::EncryptedFile *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ752_i26OA4qYu6Ypfu&open=AZ752_i26OA4qYu6Ypfu&pullRequest=10244
{
QJsonObject file;
file.insert("key", QString(encryptedFile->encryptionKey.toBase64()));
Expand Down Expand Up @@ -618,7 +623,7 @@
}

QJsonObject files, folders;
for (auto it = _files.constBegin(), end = _files.constEnd(); it != end; ++it) {

Check warning on line 626 in src/libsync/foldermetadata.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "end" of type "class QList<struct OCC::FolderMetadata::EncryptedFile>::const_iterator" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ752_i26OA4qYu6Ypfy&open=AZ752_i26OA4qYu6Ypfy&pullRequest=10244
const auto file = convertFileToJsonObject(&(*it));
if (file.isEmpty()) {
qCWarning(lcCseMetadata) << "Metadata generation failed for file" << it->encryptedFilename;
Expand All @@ -635,7 +640,7 @@

QJsonArray keyChecksums;
if (_isRootEncryptedFolder) {
for (auto it = _keyChecksums.constBegin(), end = _keyChecksums.constEnd(); it != end; ++it) {

Check warning on line 643 in src/libsync/foldermetadata.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "end" of type "class QSet<class QByteArray>::const_iterator" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ752_i26OA4qYu6Ypf0&open=AZ752_i26OA4qYu6Ypf0&pullRequest=10244
keyChecksums.push_back(QJsonValue::fromVariant(*it));
}
}
Expand Down Expand Up @@ -1060,7 +1065,7 @@
}

auto convertedCertificateType = CertificateInformation::CertificateType::HardwareCertificate;
switch (certificateType)

Check failure on line 1068 in src/libsync/foldermetadata.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=AZ752_i26OA4qYu6YpgG&open=AZ752_i26OA4qYu6YpgG&pullRequest=10244
{
case CertificateType::HardwareCertificate:
convertedCertificateType = CertificateInformation::CertificateType::HardwareCertificate;
Expand Down
3 changes: 2 additions & 1 deletion src/libsync/foldermetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace OCC
{
// Handles parsing and altering the metadata, encryption and decryption. Setup of the instance is always asynchronouse and emits void setupComplete()
class OWNCLOUDSYNC_EXPORT FolderMetadata : public QObject

Check warning on line 27 in src/libsync/foldermetadata.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Class has 59 methods, which is greater than the 35 authorized. Split it into smaller classes.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ752_i_6OA4qYu6YpgN&open=AZ752_i_6OA4qYu6YpgN&pullRequest=10244
{
friend class ::TestClientSideEncryptionV2;
friend class ::TestSecureFileDrop;
Expand Down Expand Up @@ -92,7 +92,7 @@
};
Q_ENUM(MetadataVersion)

FolderMetadata(AccountPtr account, const QString &remoteFolderRoot, FolderType folderType = FolderType::Nested);
FolderMetadata(AccountPtr account, const QString &remoteFolderRoot, FolderType folderType);
/*
* construct metadata based on RootEncryptedFolderInfo
* as per E2EE V2, the encryption key and users that have access are only stored in root(top-level) encrypted folder's metadata
Expand All @@ -103,6 +103,7 @@
const QByteArray &metadata,
const RootEncryptedFolderInfo &rootEncryptedFolderInfo,
const QByteArray &signature,
FolderType folderType,
QObject *parent = nullptr);

[[nodiscard]] QVector<EncryptedFile> files() const;
Expand Down Expand Up @@ -177,8 +178,8 @@

void setFileDrop(const QJsonObject &fileDrop);

static EncryptionStatusEnums::ItemEncryptionStatus fromMedataVersionToItemEncryptionStatus(const MetadataVersion metadataVersion);

Check warning on line 181 in src/libsync/foldermetadata.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=AZ752_i_6OA4qYu6YpgR&open=AZ752_i_6OA4qYu6YpgR&pullRequest=10244
static MetadataVersion fromItemEncryptionStatusToMedataVersion(const EncryptionStatusEnums::ItemEncryptionStatus encryptionStatus);

Check warning on line 182 in src/libsync/foldermetadata.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=AZ752_i_6OA4qYu6YpgS&open=AZ752_i_6OA4qYu6YpgS&pullRequest=10244

static QByteArray prepareMetadataForSignature(const QJsonDocument &fullMetadata);

Expand All @@ -190,7 +191,7 @@
void setupExistingMetadata(const QByteArray &metadata);
void setupExistingMetadataLegacy(const QByteArray &metadata);

void startFetchRootE2eeFolderMetadata(const QString &path);

Check warning on line 194 in src/libsync/foldermetadata.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=AZ752_i_6OA4qYu6YpgT&open=AZ752_i_6OA4qYu6YpgT&pullRequest=10244
void slotRootE2eeFolderMetadataReceived(int statusCode, const QString &message);

void updateUsersEncryptedMetadataKey();
Expand Down
13 changes: 8 additions & 5 deletions test/testclientsideencryptionv2.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-2.0-or-later
Expand Down Expand Up @@ -176,7 +176,7 @@

QScopedPointer<FolderMetadata> metadataFromJson(new FolderMetadata(_account, "/",
ocsDoc.toJson(),
RootEncryptedFolderInfo::makeDefault(), signature));
RootEncryptedFolderInfo::makeDefault(), signature, FolderMetadata::FolderType::Root));
QSignalSpy metadataSetupExistingCompleteSpy(metadataFromJson.data(), &FolderMetadata::setupComplete);
metadataSetupExistingCompleteSpy.wait();
QCOMPARE(metadataSetupExistingCompleteSpy.count(), 1);
Expand Down Expand Up @@ -208,7 +208,8 @@
QScopedPointer<FolderMetadata> metadataFromJson(new FolderMetadata(_account, "/",
ocsDoc.toJson(),
RootEncryptedFolderInfo::makeDefault(),
emptySignature));
emptySignature,
FolderMetadata::FolderType::Root));

QSignalSpy metadataSetupExistingCompleteSpy(metadataFromJson.data(), &FolderMetadata::setupComplete);
metadataSetupExistingCompleteSpy.wait();
Expand Down Expand Up @@ -314,7 +315,7 @@
QJsonDocument ocsDoc =
QJsonDocument::fromJson(QStringLiteral("{\"ocs\": {\"data\": {\"meta-data\": \"%1\"}}}").arg(QString::fromUtf8(encryptedMetadataCopy)).toUtf8());

QScopedPointer<FolderMetadata> metadataFromJsonForSecondUser(new FolderMetadata(_secondAccount, "/", ocsDoc.toJson(), RootEncryptedFolderInfo::makeDefault(), signature));
QScopedPointer<FolderMetadata> metadataFromJsonForSecondUser(new FolderMetadata(_secondAccount, "/", ocsDoc.toJson(), RootEncryptedFolderInfo::makeDefault(), signature, FolderMetadata::FolderType::Root));
QSignalSpy metadataSetupExistingCompleteSpy(metadataFromJsonForSecondUser.data(), &FolderMetadata::setupComplete);
metadataSetupExistingCompleteSpy.wait();
QCOMPARE(metadataSetupExistingCompleteSpy.count(), 1);
Expand All @@ -338,10 +339,12 @@
QJsonDocument ocsDocFromSecondUser = QJsonDocument::fromJson(
QStringLiteral("{\"ocs\": {\"data\": {\"meta-data\": \"%1\"}}}").arg(QString::fromUtf8(encryptedMetadataFromSecondUser)).toUtf8());

QScopedPointer<FolderMetadata> metadataFromJsonForFirstUserToCheckCrossSharing(new FolderMetadata(_account, "/",
QScopedPointer<FolderMetadata> metadataFromJsonForFirstUserToCheckCrossSharing(new FolderMetadata(_account,
"/",
ocsDocFromSecondUser.toJson(),
RootEncryptedFolderInfo::makeDefault(),
signatureAfterSecondUserModification));
signatureAfterSecondUserModification,
FolderMetadata::FolderType::Root));
QSignalSpy metadataSetupForCrossSharingCompleteSpy(metadataFromJsonForFirstUserToCheckCrossSharing.data(), &FolderMetadata::setupComplete);
metadataSetupForCrossSharingCompleteSpy.wait();
QCOMPARE(metadataSetupForCrossSharingCompleteSpy.count(), 1);
Expand Down
4 changes: 2 additions & 2 deletions test/testsecurefiledrop.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-2.0-or-later
Expand Down Expand Up @@ -141,7 +141,7 @@
const auto signature = metadata->metadataSignature();
QJsonDocument ocsDoc =
QJsonDocument::fromJson(QStringLiteral("{\"ocs\": {\"data\": {\"meta-data\": \"%1\"}}}").arg(QString::fromUtf8(encryptedMetadata)).toUtf8());
_parsedMetadataWithFileDrop.reset(new FolderMetadata(_account, "/", ocsDoc.toJson(), RootEncryptedFolderInfo::makeDefault(), signature));
_parsedMetadataWithFileDrop.reset(new FolderMetadata(_account, "/", ocsDoc.toJson(), RootEncryptedFolderInfo::makeDefault(), signature, FolderMetadata::FolderType::Root));

QSignalSpy metadataWithFileDropSetupCompleteSpy(_parsedMetadataWithFileDrop.data(), &FolderMetadata::setupComplete);
metadataWithFileDropSetupCompleteSpy.wait();
Expand All @@ -164,7 +164,7 @@
QJsonDocument ocsDoc =
QJsonDocument::fromJson(QStringLiteral("{\"ocs\": {\"data\": {\"meta-data\": \"%1\"}}}").arg(QString::fromUtf8(encryptedMetadata)).toUtf8());

_parsedMetadataAfterProcessingFileDrop.reset(new FolderMetadata(_account, "/", ocsDoc.toJson(), RootEncryptedFolderInfo::makeDefault(), signature));
_parsedMetadataAfterProcessingFileDrop.reset(new FolderMetadata(_account, "/", ocsDoc.toJson(), RootEncryptedFolderInfo::makeDefault(), signature, FolderMetadata::FolderType::Root));

QSignalSpy metadataAfterProcessingFileDropSetupCompleteSpy(_parsedMetadataAfterProcessingFileDrop.data(), &FolderMetadata::setupComplete);
metadataAfterProcessingFileDropSetupCompleteSpy.wait();
Expand Down
Loading