owncloudcmd: add --max-sync-retries #4037

And limit by default to 3 retries
This commit is contained in:
Olivier Goffart 2015-10-30 13:35:00 +01:00
parent 0c467ef5b4
commit 16c078963b

View 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;