From f2122f47cb798cc4d408c50ab22794e0b45978bf Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Tue, 25 Jun 2024 20:39:09 +0200 Subject: [PATCH] Add sync option for nextcloudcmd. Signed-off-by: Camila Ayres --- src/cmd/cmd.cpp | 1 + src/libsync/syncengine.cpp | 3 ++- src/libsync/syncoptions.cpp | 11 +++++++++++ src/libsync/syncoptions.h | 7 ++++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/cmd/cmd.cpp b/src/cmd/cmd.cpp index 2a1be09c701ce..3c940ee2e9adc 100644 --- a/src/cmd/cmd.cpp +++ b/src/cmd/cmd.cpp @@ -532,6 +532,7 @@ int main(int argc, char **argv) SyncOptions syncOptions; syncOptions.fillFromEnvironmentVariables(); syncOptions.verifyChunkSizes(); + syncOptions.setIsCmd(true); SyncEngine engine(account, options.source_dir, syncOptions, folder, &db); engine.setIgnoreHiddenFiles(options.ignoreHiddenFiles); engine.setNetworkLimits(options.uplimit, options.downlimit); diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index 77fcf5174f1a7..1f130967599a0 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -898,7 +898,8 @@ void SyncEngine::slotDiscoveryFinished() qCInfo(lcEngine) << "#### Post-Reconcile end #################################################### " << _stopWatch.addLapTime(QStringLiteral("Post-Reconcile Finished")) << "ms"; }; - if (!_hasNoneFiles && _hasRemoveFile && ConfigFile().promptDeleteFiles()) { + const auto displayDialog = ConfigFile().promptDeleteFiles() && !_syncOptions.isCmd(); + if (!_hasNoneFiles && _hasRemoveFile && displayDialog) { qCInfo(lcEngine) << "All the files are going to be changed, asking the user"; int side = 0; // > 0 means more deleted on the server. < 0 means more deleted on the client for (const auto &it : _syncItems) { diff --git a/src/libsync/syncoptions.cpp b/src/libsync/syncoptions.cpp index c11d3a9bba2b1..1585317a859ea 100644 --- a/src/libsync/syncoptions.cpp +++ b/src/libsync/syncoptions.cpp @@ -21,6 +21,7 @@ using namespace OCC; SyncOptions::SyncOptions() : _vfs(new VfsOff) + , _isCmd(false) { } @@ -91,3 +92,13 @@ void SyncOptions::setPathPattern(const QString &pattern) _fileRegex.setPatternOptions(Utility::fsCasePreserving() ? QRegularExpression::CaseInsensitiveOption : QRegularExpression::NoPatternOption); _fileRegex.setPattern(pattern); } + +void SyncOptions::setIsCmd(const bool isCmd) +{ + _isCmd = isCmd; +} + +bool SyncOptions::isCmd() const +{ + return _isCmd; +} diff --git a/src/libsync/syncoptions.h b/src/libsync/syncoptions.h index 092ac6fb6f1c6..12c93fef99c51 100644 --- a/src/libsync/syncoptions.h +++ b/src/libsync/syncoptions.h @@ -93,7 +93,6 @@ class OWNCLOUDSYNC_EXPORT SyncOptions */ void verifyChunkSizes(); - /** A regular expression to match file names * If no pattern is provided the default is an invalid regular expression. */ @@ -109,6 +108,10 @@ class OWNCLOUDSYNC_EXPORT SyncOptions */ void setPathPattern(const QString &pattern); + /** sync had been started via nextcloudcmd command line */ + [[nodiscard]] bool isCmd() const; + void setIsCmd(const bool isCmd); + private: /** * Only sync files that match the expression @@ -118,6 +121,8 @@ class OWNCLOUDSYNC_EXPORT SyncOptions qint64 _minChunkSize = chunkV2MinChunkSize; qint64 _maxChunkSize = chunkV2MaxChunkSize; + + bool _isCmd; }; }