owncloudcmd: add --max-sync-retries #4037
authorOlivier Goffart <ogoffart@woboq.com>
Fri, 30 Oct 2015 12:35:00 +0000 (13:35 +0100)
committerOlivier Goffart <ogoffart@woboq.com>
Fri, 30 Oct 2015 12:36:31 +0000 (13:36 +0100)
And limit by default to 3 retries

src/cmd/cmd.cpp

index 0ac513809e00ca893069326208ee06a6c4ecc71b..85e07a3a87584aba8f032f9b9f6fdd0ef8a95756 100644 (file)
@@ -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;