Skip to content

Commit

Permalink
proper stop on -d flag
Browse files Browse the repository at this point in the history
  • Loading branch information
seletskiy committed May 26, 2016
1 parent 81441c6 commit dd20af6
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ Restrictions:
Usage:
orgalorg -h | --help
orgalorg [options] (-o <host>...|-s) -S <files>... [-d]
orgalorg [options] (-o <host>...|-s) -S <files>... [(-d|--stop-at-upload)]
orgalorg [options] (-o <host>...|-s) -C <command>...
orgalorg [options] (-o <host>...|-s) (-L | --stop-at-lock)
orgalorg [options] (-o <host>...|-s) (-L|--stop-at-lock)
Operation modes:
-S --sync Sync.
Expand Down Expand Up @@ -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["<files>"].([]string)
relative = args["--relative"].(bool)
)
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -268,8 +291,6 @@ func synchronize(args map[string]interface{}) error {
)
}

logger.Info(`upload done`)

return nil
}

Expand Down

0 comments on commit dd20af6

Please sign in to comment.