From dd20af659611f3a7c1a5eb3b3eb8cfe2b6a11063 Mon Sep 17 00:00:00 2001 From: Stanislav Seletskiy Date: Thu, 26 May 2016 22:28:15 +0600 Subject: [PATCH] proper stop on -d flag --- main.go | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 92a721c..d6186ce 100644 --- a/main.go +++ b/main.go @@ -42,9 +42,9 @@ Restrictions: Usage: orgalorg -h | --help - orgalorg [options] (-o ...|-s) -S ... [-d] + orgalorg [options] (-o ...|-s) -S ... [(-d|--stop-at-upload)] orgalorg [options] (-o ...|-s) -C ... - orgalorg [options] (-o ...|-s) (-L | --stop-at-lock) + orgalorg [options] (-o ...|-s) (-L|--stop-at-lock) Operation modes: -S --sync Sync. @@ -187,6 +187,7 @@ func main() { func synchronize(args map[string]interface{}) error { var ( lockOnly = args["--stop-at-lock"].(bool) + uploadOnly = args["--stop-at-upload"].(bool) || args["-d"].(bool) fileSources = args[""].([]string) relative = args["--relative"].(bool) ) @@ -232,7 +233,7 @@ func synchronize(args map[string]interface{}) error { logger.Infof(`global lock acquired on %d nodes`, len(cluster.nodes)) if lockOnly { - logger.Info("--stop-at-lock was passed, waiting for interrupt...") + logger.Info("-L|--stop-at-lock was passed, waiting for interrupt...") wait := sync.WaitGroup{} wait.Add(1) @@ -241,6 +242,28 @@ func synchronize(args map[string]interface{}) error { os.Exit(0) } + err = upload(args, cluster, filesList) + if err != nil { + return hierr.Errorf( + err, + `can't upload files on the remote nodes`, + ) + } + + logger.Info(`upload done`) + + if uploadOnly { + logger.Info("-d|--stop-at-upload was passed, finishing...") + } + + return nil +} + +func upload( + args map[string]interface{}, + cluster *distributedLock, + filesList []string, +) error { receivers, err := startArchiveReceivers(cluster, args) if err != nil { return hierr.Errorf( @@ -268,8 +291,6 @@ func synchronize(args map[string]interface{}) error { ) } - logger.Info(`upload done`) - return nil }