From 16c078963b375fac4cb820ff9f3703c80711d3a2 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 30 Oct 2015 13:35:00 +0100 Subject: [PATCH] owncloudcmd: add --max-sync-retries #4037 And limit by default to 3 retries --- src/cmd/cmd.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cmd/cmd.cpp b/src/cmd/cmd.cpp index 0ac513809..85e07a3a8 100644 --- a/src/cmd/cmd.cpp +++ b/src/cmd/cmd.cpp @@ -58,6 +58,7 @@ struct CmdOptions { bool ignoreHiddenFiles; QString exclude; QString unsyncedfolders; + int restartTimes; }; // we can't use csync_set_userdata because the SyncEngine sets it already. @@ -155,6 +156,7 @@ void help() std::cout << " --password, -p [pass] Use [pass] as password" << std::endl; std::cout << " -n Use netrc (5) for login" << std::endl; std::cout << " --non-interactive Do not block execution with interaction" << std::endl; + std::cout << " --max-sync-retries [n] Retries maximum n times (default to 3)" << std::endl; std::cout << " -h Sync hidden files,do not ignore them" << std::endl; std::cout << " --version, -v Display version and exit" << std::endl; std::cout << "" << std::endl; @@ -222,6 +224,8 @@ void parseOptions( const QStringList& app_args, CmdOptions *options ) options->exclude = it.next(); } else if( option == "--unsyncedfolders" && !it.peekNext().startsWith("-") ) { options->unsyncedfolders = it.next(); + } else if( option == "--max-sync-retries" && !it.peekNext().startsWith("-") ) { + options->restartTimes = it.next().toInt(); } else { help(); } @@ -268,6 +272,7 @@ int main(int argc, char **argv) { options.useNetrc = false; options.interactive = true; options.ignoreHiddenFiles = true; + options.restartTimes = 3; ClientProxy clientProxy; parseOptions( app.arguments(), &options ); @@ -356,6 +361,7 @@ int main(int argc, char **argv) { account->setCredentials(cred); account->setSslErrorHandler(sslErrorHandler); + int restartCount = 0; restart_sync: CSYNC *_csync_ctx; @@ -458,8 +464,12 @@ restart_sync: csync_destroy(_csync_ctx); if (engine.isAnotherSyncNeeded()) { - qDebug() << "Restarting Sync, because another sync is needed"; - goto restart_sync; + if (restartCount < options.restartTimes) { + restartCount++; + qDebug() << "Restarting Sync, because another sync is needed" << restartCount; + goto restart_sync; + } + qWarning() << "Another sync is needed, but not done because restart count is exceeded" << restartCount; } return 0; -- 2.30.2