diff --git a/Sync/main.cpp b/Sync/main.cpp index b07213e..0a28a1e 100644 --- a/Sync/main.cpp +++ b/Sync/main.cpp @@ -26,11 +26,69 @@ int main(int argc, char **argv) { QCoreApplication::setApplicationName("ATBUpdateSync"); QCoreApplication::setApplicationVersion(APP_VERSION); + QDebug debug = qCritical(); + if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling atbInstallMessageHandler(nullptr); //atbInstallMessageHandler(atbDebugOutput); setDebugLevel(LOG_NOTICE); } - return 0; + if (internal::customerRepoExists() == false) { + qCritical().noquote() << internal::NO_CUSTOMER_REPOSITORY; + return internal::NO_CUSTOMER_REPOSITORY_CODE; + } + + QString const crd = internal::customerRepoDir(); + QString const etcInRepo = QDir::cleanPath(crd + QDir::separator() + "etc/"); + QString const optInRepo = QDir::cleanPath(crd + QDir::separator() + "opt/"); + + if (!QDir(etcInRepo).exists()) { + qCritical().noquote() << internal::NO_ETC_CUSTOMER_REPOSITORY; + return internal::NO_ETC_CUSTOMER_REPOSITORY_CODE; + } + + if (!QDir(optInRepo).exists()) { + qCritical().noquote() << internal::NO_OPT_CUSTOMER_REPOSITORY; + return internal::NO_OPT_CUSTOMER_REPOSITORY_CODE; + } + +#if 0 + error codes for rsync: + https://stackoverflow.com/questions/20737204/comprehensive-list-of-rsync-error-codes + + 0 Success + 1 Syntax or usage error + 2 Protocol incompatibility + 3 Errors selecting input/output files, dirs + 4 Requested action not supported: an attempt was made to manipulate 64-bit + files on a platform that cannot support them; or an option was specified + that is supported by the client and not by the server. + 5 Error starting client-server protocol + 6 Daemon unable to append to log-file + 10 Error in socket I/O + 11 Error in file I/O + 12 Error in rsync protocol data stream + 13 Errors with program diagnostics + 14 Error in IPC code + 20 Received SIGUSR1 or SIGINT + 21 Some error returned by waitpid() + 22 Error allocating core memory buffers + 23 Partial transfer due to error + 24 Partial transfer due to vanished source files + 25 The --max-delete limit stopped deletions + 30 Timeout in data send/receive + 35 Timeout waiting for daemon connection +#endif + + + QStringList options({"-v", "--recursive", "--progress", "--checksum", + "--exclude=.*", "--include=*.bin", "--include=*.json", + "--include=*.ini"}); + int ret = SyncCommand().exec("rsync", options << etcInRepo << "/etc"); + + if (ret == 0) { + ret = SyncCommand().exec("rsync", options << optInRepo << "/opt"); + } + return ret; } diff --git a/Sync/sync_command.cpp b/Sync/sync_command.cpp index 644d3d5..ff97448 100644 --- a/Sync/sync_command.cpp +++ b/Sync/sync_command.cpp @@ -12,7 +12,10 @@ using namespace internal; SyncCommand::SyncCommand() { } -bool SyncCommand::exec(QString const &cmd, QStringList const &options, +int SyncCommand::exec(QString const &cmd, QStringList const &options, int start_timeout, int finish_timeout) { - return false; + Command c(cmd, options, internal::customerRepoDir(), + start_timeout, finish_timeout); + c.exec(); + return c.exitCode(); } diff --git a/Sync/sync_command.h b/Sync/sync_command.h index 82b416f..17b19d9 100644 --- a/Sync/sync_command.h +++ b/Sync/sync_command.h @@ -7,7 +7,7 @@ class SyncCommand { public: SyncCommand(); - bool exec(QString const &cmd, QStringList const &options, + int exec(QString const &cmd, QStringList const &options, int start_timeout = 100000, int finish_timeout = 100000); };