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
5 changes: 3 additions & 2 deletions src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@

// Delete the stales chunk on the server.
if (account()->capabilities().chunkingNg()) {
for (uint transferId : std::as_const(ids)) {

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZqSerKEMrwDpt8B3BjX&open=AZqSerKEMrwDpt8B3BjX&pullRequest=9020
if (!transferId)
continue; // Was not a chunked upload
QUrl url = Utility::concatUrlPath(account()->url(), QLatin1String("remote.php/dav/uploads/") + account()->davUser() + QLatin1Char('/') + QString::number(transferId));
(new DeleteJob(account(), url, {}, this))->start();

Check failure on line 247 in src/libsync/syncengine.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=AZqSerKEMrwDpt8B3BjY&open=AZqSerKEMrwDpt8B3BjY&pullRequest=9020
}
}
}
Expand Down Expand Up @@ -382,7 +382,7 @@
const auto lockOwnerTypeToSkipReadonly = _account->capabilities().filesLockTypeAvailable()
? SyncFileItem::LockOwnerType::TokenLock
: SyncFileItem::LockOwnerType::UserLock;
if (item->_locked == SyncFileItem::LockStatus::LockedItem

Check failure on line 385 in src/libsync/syncengine.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=AZqSerKEMrwDpt8B3BjZ&open=AZqSerKEMrwDpt8B3BjZ&pullRequest=9020
&& (item->_lockOwnerType != lockOwnerTypeToSkipReadonly || item->_lockOwnerId != account()->davUser())) {
qCDebug(lcEngine()) << filePath << "file is locked: making it read only";
FileSystem::setFileReadOnly(filePath, true);
Expand All @@ -396,7 +396,7 @@

// Update on-disk virtual file metadata
if (modificationHappened && item->_type == ItemTypeVirtualFile) {
auto r = _syncOptions._vfs->updateMetadata(*item, filePath, {});

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "r" of type "class OCC::Result<enum OCC::Vfs::ConvertToPlaceholderResult, class QString>" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZqSerKEMrwDpt8B3Bja&open=AZqSerKEMrwDpt8B3Bja&pullRequest=9020
if (!r) {
item->_status = SyncFileItem::Status::NormalError;
item->_instruction = CSYNC_INSTRUCTION_ERROR;
Expand Down Expand Up @@ -473,7 +473,7 @@
_needsUpdate = true;

// Insert sorted
auto it = std::lower_bound( _syncItems.begin(), _syncItems.end(), item ); // the _syncItems is sorted

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZqSerKEMrwDpt8B3Bjb&open=AZqSerKEMrwDpt8B3Bjb&pullRequest=9020
_syncItems.insert( it, item );

slotNewItem(item);
Expand All @@ -500,15 +500,15 @@
const auto e2EeLockedFolders = _journal->e2EeLockedFolders();

if (!e2EeLockedFolders.isEmpty()) {
for (const auto &e2EeLockedFolder : e2EeLockedFolders) {

Check warning on line 503 in src/libsync/syncengine.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=AZqSerKEMrwDpt8B3Bje&open=AZqSerKEMrwDpt8B3Bje&pullRequest=9020
const auto folderId = e2EeLockedFolder.first;

Check warning on line 504 in src/libsync/syncengine.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=AZqSerKEMrwDpt8B3Bjf&open=AZqSerKEMrwDpt8B3Bjf&pullRequest=9020
qCInfo(lcEngine()) << "start unlock job for folderId:" << folderId;
const auto folderToken = EncryptionHelper::decryptStringAsymmetric(_account->e2e()->getCertificateInformation(), _account->e2e()->paddingMode(), *_account->e2e(), e2EeLockedFolder.second);
if (!folderToken) {

Check failure on line 507 in src/libsync/syncengine.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=AZqSerKEMrwDpt8B3Bjd&open=AZqSerKEMrwDpt8B3Bjd&pullRequest=9020
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 511 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=AZqSerKEMrwDpt8B3BjV&open=AZqSerKEMrwDpt8B3BjV&pullRequest=9020
const auto unlockJob = new OCC::UnlockEncryptFolderApiJob(_account, folderId, *folderToken, _journal, this);
unlockJob->setShouldRollbackMetadataChanges(true);
unlockJob->start();
Expand Down Expand Up @@ -636,7 +636,7 @@
_discoveryPhase->_account = _account;
_discoveryPhase->_excludes = _excludedFiles.data();
const QString excludeFilePath = _localPath + QStringLiteral(".sync-exclude.lst");
if (FileSystem::fileExists(excludeFilePath)) {

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZqSerKEMrwDpt8B3Bjc&open=AZqSerKEMrwDpt8B3Bjc&pullRequest=9020
_discoveryPhase->_excludes->addExcludeFilePath(excludeFilePath);
_discoveryPhase->_excludes->reloadExcludeFiles();
}
Expand All @@ -645,7 +645,7 @@
_discoveryPhase->_remoteFolder = Utility::trailingSlashPath(_remotePath);
_discoveryPhase->_syncOptions = _syncOptions;
_discoveryPhase->_shouldDiscoverLocaly = [this](const QString &path) {
const auto result = shouldDiscoverLocally(path);

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

declaration shadows a local variable

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZqSerKEMrwDpt8B3BjW&open=AZqSerKEMrwDpt8B3BjW&pullRequest=9020
return result;
};
_discoveryPhase->setSelectiveSyncBlackList(selectiveSyncBlackList);
Expand Down Expand Up @@ -698,7 +698,7 @@
connect(_discoveryPhase.get(), &DiscoveryPhase::itemDiscovered, this, &SyncEngine::slotItemDiscovered);
connect(_discoveryPhase.get(), &DiscoveryPhase::newBigFolder, this, &SyncEngine::newBigFolder);
connect(_discoveryPhase.get(), &DiscoveryPhase::existingFolderNowBig, this, &SyncEngine::existingFolderNowBig);
connect(_discoveryPhase.get(), &DiscoveryPhase::fatalError, this, [this](const QString &errorString, ErrorCategory errorCategory) {

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "errorCategory" of type "enum OCC::ErrorCategory" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZqSerKEMrwDpt8B3Bjg&open=AZqSerKEMrwDpt8B3Bjg&pullRequest=9020
Q_EMIT syncError(errorString, errorCategory);
finalize(false);
});
Expand Down Expand Up @@ -847,7 +847,7 @@

if (isNewlyUploadedFile && item->_locked != SyncFileItem::LockStatus::LockedItem && _account->capabilities().filesLockAvailable() &&
FileSystem::isMatchingOfficeFileExtension(item->_file)) {
{

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested code block into a separate function.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZqSerKEMrwDpt8B3Bjh&open=AZqSerKEMrwDpt8B3Bjh&pullRequest=9020
SyncJournalFileRecord rec;
if (!_journal->getFileRecord(item->_file, &rec) || !rec.isValid()) {
qCWarning(lcEngine) << "Newly-created office file just uploaded but not in sync journal. Not going to lock it." << item->_file;
Expand Down Expand Up @@ -892,7 +892,7 @@
detectFileLock(item);
}

void SyncEngine::slotPropagationFinished(OCC::SyncFileItem::Status status)

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZqSerKEMrwDpt8B3Bji&open=AZqSerKEMrwDpt8B3Bji&pullRequest=9020
{
if (_propagator->_anotherSyncNeeded && _anotherSyncNeeded == NoFollowUpSync) {
_anotherSyncNeeded = ImmediateFollowUp;
Expand Down Expand Up @@ -1007,7 +1007,7 @@
}
}

void SyncEngine::cancelSyncOrContinue(bool cancel)

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZqSerKEMrwDpt8B3Bjj&open=AZqSerKEMrwDpt8B3Bjj&pullRequest=9020
{
if (cancel) {
qCInfo(lcEngine) << "User aborted sync";
Expand Down Expand Up @@ -1113,7 +1113,7 @@
qCInfo(lcEngine) << "#### Post-Reconcile end #################################################### " << _stopWatch.addLapTime(QStringLiteral("Post-Reconcile Finished")) << "ms";
}

bool SyncEngine::handleMassDeletion()

Check failure on line 1116 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=AZqSerKEMrwDpt8B3Bjl&open=AZqSerKEMrwDpt8B3Bjl&pullRequest=9020
{
const auto displayDialog = ConfigFile().promptDeleteFiles() && !_syncOptions.isCmd();
const auto allFilesDeleted = !_hasNoneFiles && _hasRemoveFile;
Expand All @@ -1123,11 +1123,11 @@
if (oneItem->_instruction == CSYNC_INSTRUCTION_REMOVE) {
if (oneItem->isDirectory()) {
const auto result = _journal->listFilesInPath(oneItem->_file.toUtf8(), [&deletionCounter] (const auto &oneRecord) {
if (oneRecord.isFile()) {

Check failure on line 1126 in src/libsync/syncengine.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=AZqSerKEMrwDpt8B3Bjm&open=AZqSerKEMrwDpt8B3Bjm&pullRequest=9020
++deletionCounter;
}
});
if (!result) {

Check failure on line 1130 in src/libsync/syncengine.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=AZqSerKEMrwDpt8B3Bjn&open=AZqSerKEMrwDpt8B3Bjn&pullRequest=9020
qCDebug(lcEngine()) << "unable to find the number of files within a deleted folder:" << oneItem->_file;
}
} else {
Expand All @@ -1137,7 +1137,7 @@
}
const auto filesDeletedThresholdExceeded = deletionCounter > ConfigFile().deleteFilesThreshold();

if ((allFilesDeleted || filesDeletedThresholdExceeded) && displayDialog) {

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZqSerKEMrwDpt8B3Bjk&open=AZqSerKEMrwDpt8B3Bjk&pullRequest=9020
qCWarning(lcEngine) << "Many files are going to be deleted, asking the user";
int side = 0; // > 0 means more deleted on the server. < 0 means more deleted on the client
for (const auto &it : std::as_const(_syncItems)) {
Expand All @@ -1146,7 +1146,7 @@
}
}

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

Check failure on line 1149 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=AZqSerKEMrwDpt8B3Bjo&open=AZqSerKEMrwDpt8B3Bjo&pullRequest=9020
emit aboutToRemoveAllFiles(side >= 0 ? SyncFileItem::Down : SyncFileItem::Up, callback);
});
return true;
Expand All @@ -1171,7 +1171,7 @@
slotAddTouchedFile(_localPath + oneFolder->_file);

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

Check warning on line 1174 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=AZqSerKEMrwDpt8B3Bjp&open=AZqSerKEMrwDpt8B3Bjp&pullRequest=9020
slotAddTouchedFile(deleteItem);
};
FileSystem::removeRecursively(_localPath + oneFolder->_file, deletionCallback, nullptr, deletionCallback);
Expand All @@ -1186,7 +1186,7 @@
{
QPointer<QObject> guard = new QObject();
QPointer<QObject> self = this;
auto callback = [this, self, guard](bool cancel) -> void {

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the redundant return type of this lambda.

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

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZqSerKEMrwDpt8B3Bjr&open=AZqSerKEMrwDpt8B3Bjr&pullRequest=9020
// use a guard to ensure its only called once...
// qpointer to self to ensure we still exist
if (!guard || !self) {
Expand All @@ -1198,7 +1198,7 @@
};

lambda(callback);
}

Check failure on line 1201 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=AZqSerKEMrwDpt8B3Bjw&open=AZqSerKEMrwDpt8B3Bjw&pullRequest=9020

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

void SyncEngine::setLocalDiscoveryEnforceWindowsFileNameCompatibility(bool value)

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

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

Check warning on line 1239 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=AZqSerKEMrwDpt8B3Bjs&open=AZqSerKEMrwDpt8B3Bjs&pullRequest=9020
{
_shouldEnforceWindowsFileNameCompatibility = value;
}
Expand All @@ -1261,7 +1261,7 @@
// only execute if logging is enabled
auto debug = qDebug(lcEngine);
debug << "paths to discover locally";
for (auto path : _localDiscoveryPaths) {
for (const auto &path : _localDiscoveryPaths) {
debug << path;
}
}
Expand All @@ -1273,14 +1273,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 1283 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=AZqSerKEMrwDpt8B3Bju&open=AZqSerKEMrwDpt8B3Bju&pullRequest=9020
}

void SyncEngine::setSingleItemDiscoveryOptions(const SingleItemDiscoveryOptions &singleItemDiscoveryOptions)
Expand Down Expand Up @@ -1354,8 +1354,9 @@
{
qCInfo(lcEngine) << "Wiping virtual files inside" << localPath;
const auto resGetFilesBelowPath = journal.getFilesBelowPath(QByteArray(), [&](const SyncJournalFileRecord &rec) {
if (rec._type != ItemTypeVirtualFile && rec._type != ItemTypeVirtualFileDownload)
if (rec._type != ItemTypeVirtualFile && rec._type != ItemTypeVirtualFileDownload && rec._type != ItemTypeVirtualDirectory) {
return;
}

qCDebug(lcEngine) << "Removing db record for" << rec.path();
if (!journal.deleteFileRecord(rec._path)) {
Expand Down Expand Up @@ -1525,7 +1526,7 @@
it != _discoveryPhase->_filesNeedingScheduledSync.cend();
++it) {

const auto file = it.key();

Check warning on line 1529 in src/libsync/syncengine.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=AZqSerKEMrwDpt8B3Bjv&open=AZqSerKEMrwDpt8B3Bjv&pullRequest=9020
const auto syncScheduledSecs = it.value();

// We don't want to schedule syncs again for files we have already discovered needing a
Expand Down
71 changes: 68 additions & 3 deletions test/testsynccfapi.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: CC0-1.0
Expand All @@ -7,14 +7,15 @@
* any purpose.
*/

#include <QtTest>
#include "syncenginetestutils.h"

#include "common/vfs.h"
#include "config.h"
#include <syncengine.h>
#include "openfilemanager.h"
#include "syncengine.h"
#include "vfs/cfapi/cfapiwrapper.h"

#include <QtTest>

namespace cfapi {
using namespace OCC::CfApiWrapper;
}
Expand Down Expand Up @@ -1576,6 +1577,70 @@

QVERIFY(fakeFolder.syncOnce());
}

void switchVfsOffWithOnDemandFolder()
{
FakeFolder fakeFolder{FileInfo{}};
setupVfs(fakeFolder);

ItemCompletedSpy completeSpy(fakeFolder);

fakeFolder.remoteModifier().insert("firstFile1.txt");
fakeFolder.remoteModifier().insert("firstFile2.txt");
fakeFolder.remoteModifier().insert("firstFile3.txt");
fakeFolder.remoteModifier().mkdir("directory");
fakeFolder.remoteModifier().mkdir("directory/subdir");
fakeFolder.remoteModifier().insert("directory/file1");
fakeFolder.remoteModifier().insert("directory/file2");
fakeFolder.remoteModifier().insert("directory/file3");
fakeFolder.remoteModifier().insert("directory/subdir/fileTxt1.txt");
fakeFolder.remoteModifier().insert("directory/subdir/fileTxt2.txt");
fakeFolder.remoteModifier().insert("directory/subdir/fileTxt3.txt");

QVERIFY(fakeFolder.syncOnce());

QCOMPARE(completeSpy.size(), 4);
QVERIFY(itemInstruction(completeSpy, "directory", CSYNC_INSTRUCTION_NEW));
QVERIFY(itemInstruction(completeSpy, "firstFile1.txt", CSYNC_INSTRUCTION_NEW));
QVERIFY(itemInstruction(completeSpy, "firstFile2.txt", CSYNC_INSTRUCTION_NEW));
QVERIFY(itemInstruction(completeSpy, "firstFile3.txt", CSYNC_INSTRUCTION_NEW));
completeSpy.clear();

SyncEngine::wipeVirtualFiles(fakeFolder.localPath(), fakeFolder.syncJournal(), *fakeFolder.syncEngine().syncOptions()._vfs);

fakeFolder.syncEngine().syncOptions()._vfs->stop();
fakeFolder.syncEngine().syncOptions()._vfs->unregisterFolder();

auto noVfsPlugin = QSharedPointer<Vfs>(createVfsFromPlugin(Vfs::Off).release());
QObject::connect(&fakeFolder.syncEngine().syncFileStatusTracker(), &SyncFileStatusTracker::fileStatusChanged,
noVfsPlugin.data(), &Vfs::fileStatusChanged);
fakeFolder.switchToVfs(noVfsPlugin);

::setPinState(fakeFolder.localPath(), PinState::Unspecified, cfapi::NoRecurse);

fakeFolder.syncJournal().setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, {});

fakeFolder.syncEngine().setLocalDiscoveryOptions(LocalDiscoveryStyle::FilesystemOnly);
QVERIFY(fakeFolder.syncOnce());

QCOMPARE(completeSpy.size(), 11);
QVERIFY(itemInstruction(completeSpy, "directory", CSYNC_INSTRUCTION_NEW));
QVERIFY(itemInstruction(completeSpy, "firstFile1.txt", CSYNC_INSTRUCTION_NEW));
QVERIFY(itemInstruction(completeSpy, "firstFile2.txt", CSYNC_INSTRUCTION_NEW));
QVERIFY(itemInstruction(completeSpy, "firstFile3.txt", CSYNC_INSTRUCTION_NEW));
QVERIFY(itemInstruction(completeSpy, "directory/subdir", CSYNC_INSTRUCTION_NEW));
QVERIFY(itemInstruction(completeSpy, "directory/file1", CSYNC_INSTRUCTION_NEW));
QVERIFY(itemInstruction(completeSpy, "directory/file2", CSYNC_INSTRUCTION_NEW));
QVERIFY(itemInstruction(completeSpy, "directory/file3", CSYNC_INSTRUCTION_NEW));
QVERIFY(itemInstruction(completeSpy, "directory/subdir/fileTxt1.txt", CSYNC_INSTRUCTION_NEW));
QVERIFY(itemInstruction(completeSpy, "directory/subdir/fileTxt2.txt", CSYNC_INSTRUCTION_NEW));
QVERIFY(itemInstruction(completeSpy, "directory/subdir/fileTxt3.txt", CSYNC_INSTRUCTION_NEW));
Comment on lines +1627 to +1637
Copy link
Member

Choose a reason for hiding this comment

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

might be worth to verify the item direction as well to catch potential regressions early enough

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes
this is a good idea
let me work on a follow up PR to add such a check (where it would make sense)

completeSpy.clear();

fakeFolder.syncEngine().setLocalDiscoveryOptions(LocalDiscoveryStyle::FilesystemOnly);
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(completeSpy.size(), 0);
}
};

QTEST_GUILESS_MAIN(TestSyncCfApi)
Expand Down
Loading