Skip to content

Commit

Permalink
Merge pull request #4816 from nextcloud/bugfix/ensureSyncOptionsAreIn…
Browse files Browse the repository at this point in the history
…itialized

ensure SyncEngine use an initialized instance of SyncOptions
  • Loading branch information
allexzander authored Aug 8, 2022
2 parents 2d8fb14 + 8551a14 commit dab1a19
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/cmd/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ int main(int argc, char **argv)
SyncOptions opt;
opt.fillFromEnvironmentVariables();
opt.verifyChunkSizes();
SyncEngine engine(account, options.source_dir, folder, &db);
SyncEngine engine(account, options.source_dir, opt, folder, &db);
engine.setIgnoreHiddenFiles(options.ignoreHiddenFiles);
engine.setNetworkLimits(options.uplimit, options.downlimit);
QObject::connect(&engine, &SyncEngine::finished,
Expand Down
8 changes: 4 additions & 4 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Folder::Folder(const FolderDefinition &definition,

_syncResult.setFolder(_definition.alias);

_engine.reset(new SyncEngine(_accountState->account(), path(), remotePath(), &_journal));
_engine.reset(new SyncEngine(_accountState->account(), path(), initializeSyncOptions(), remotePath(), &_journal));
// pass the setting if hidden files are to be ignored, will be read in csync_update
_engine->setIgnoreHiddenFiles(_definition.ignoreHiddenFiles);

Expand Down Expand Up @@ -846,7 +846,7 @@ void Folder::startSync(const QStringList &pathList)
}

setDirtyNetworkLimits();
setSyncOptions();
syncEngine().setSyncOptions(initializeSyncOptions());

static std::chrono::milliseconds fullLocalDiscoveryInterval = []() {
auto interval = ConfigFile().fullLocalDiscoveryInterval();
Expand Down Expand Up @@ -897,7 +897,7 @@ void Folder::correctPlaceholderFiles()
}
}

void Folder::setSyncOptions()
SyncOptions Folder::initializeSyncOptions() const
{
SyncOptions opt;
ConfigFile cfgFile;
Expand All @@ -917,7 +917,7 @@ void Folder::setSyncOptions()
opt.fillFromEnvironmentVariables();
opt.verifyChunkSizes();

_engine->setSyncOptions(opt);
return opt;
}

void Folder::setDirtyNetworkLimits()
Expand Down
2 changes: 1 addition & 1 deletion src/gui/folder.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ private slots:

void checkLocalPath();

void setSyncOptions();
SyncOptions initializeSyncOptions() const;

enum LogStatus {
LogStatusRemove,
Expand Down
6 changes: 5 additions & 1 deletion src/gui/socketapi/socketuploadjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ SocketUploadJob::SocketUploadJob(const QSharedPointer<SocketApiJobV2> &job)
}

_db = new SyncJournalDb(_tmp.fileName(), this);
_engine = new SyncEngine(account->account(), _localPath.endsWith(QLatin1Char('/')) ? _localPath : _localPath + QLatin1Char('/'), _remotePath, _db);

SyncOptions opt;
opt.fillFromEnvironmentVariables();
opt.verifyChunkSizes();
_engine = new SyncEngine(account->account(), _localPath.endsWith(QLatin1Char('/')) ? _localPath : _localPath + QLatin1Char('/'), opt, _remotePath, _db);
_engine->setParent(_db);

connect(_engine, &OCC::SyncEngine::itemCompleted, this, [this](const OCC::SyncFileItemPtr item) {
Expand Down
8 changes: 6 additions & 2 deletions src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ static const std::chrono::milliseconds s_touchedFilesMaxAgeMs(3 * 1000);
// doc in header
std::chrono::milliseconds SyncEngine::minimumFileAgeForUpload(2000);

SyncEngine::SyncEngine(AccountPtr account, const QString &localPath,
const QString &remotePath, OCC::SyncJournalDb *journal)
SyncEngine::SyncEngine(AccountPtr account,
const QString &localPath,
const SyncOptions &syncOptions,
const QString &remotePath,
OCC::SyncJournalDb *journal)
: _account(account)
, _needsUpdate(false)
, _syncRunning(false)
Expand All @@ -94,6 +97,7 @@ SyncEngine::SyncEngine(AccountPtr account, const QString &localPath,
, _hasRemoveFile(false)
, _uploadLimit(0)
, _downloadLimit(0)
, _syncOptions(syncOptions)
, _anotherSyncNeeded(NoFollowUpSync)
{
qRegisterMetaType<SyncFileItem>("SyncFileItem");
Expand Down
8 changes: 6 additions & 2 deletions src/libsync/syncengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ class OWNCLOUDSYNC_EXPORT SyncEngine : public QObject
{
Q_OBJECT
public:
SyncEngine(AccountPtr account, const QString &localPath,
const QString &remotePath, SyncJournalDb *journal);
SyncEngine(AccountPtr account,
const QString &localPath,
const SyncOptions &syncOptions,
const QString &remotePath,
SyncJournalDb *journal);

~SyncEngine() override;

Q_INVOKABLE void startSync();
Expand Down
2 changes: 1 addition & 1 deletion test/syncenginetestutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ FakeFolder::FakeFolder(const FileInfo &fileTemplate, const OCC::Optional<FileInf
_account->setServerVersion(QStringLiteral("10.0.0"));

_journalDb = std::make_unique<OCC::SyncJournalDb>(localPath() + QStringLiteral(".sync_test.db"));
_syncEngine = std::make_unique<OCC::SyncEngine>(_account, localPath(), remotePath, _journalDb.get());
_syncEngine = std::make_unique<OCC::SyncEngine>(_account, localPath(), OCC::SyncOptions{}, remotePath, _journalDb.get());
// Ignore temporary files from the download. (This is in the default exclude list, but we don't load it)
_syncEngine->excludedFiles().addManualExclude(QStringLiteral("]*.~*"));

Expand Down

0 comments on commit dab1a19

Please sign in to comment.