Only allow -1 as "unlimited failures"

This commit is contained in:
Thomas Jackson 2019-01-18 09:08:50 -08:00
parent ba3f44ca28
commit 5573584fc6
1 changed files with 2 additions and 2 deletions

View File

@ -58,7 +58,7 @@ var flSyncTimeout = flag.Int("timeout", envInt("GIT_SYNC_TIMEOUT", 120),
var flOneTime = flag.Bool("one-time", envBool("GIT_SYNC_ONE_TIME", false), var flOneTime = flag.Bool("one-time", envBool("GIT_SYNC_ONE_TIME", false),
"exit after the initial checkout") "exit after the initial checkout")
var flMaxSyncFailures = flag.Int("max-sync-failures", envInt("GIT_SYNC_MAX_SYNC_FAILURES", 0), var flMaxSyncFailures = flag.Int("max-sync-failures", envInt("GIT_SYNC_MAX_SYNC_FAILURES", 0),
"the number of consecutive failures allowed before aborting (the first pull must succeed, <0 allows for infinite failures)") "the number of consecutive failures allowed before aborting (the first pull must succeed, -1 disables aborting for any number of failures after the initial sync)")
var flChmod = flag.Int("change-permissions", envInt("GIT_SYNC_PERMISSIONS", 0), var flChmod = flag.Int("change-permissions", envInt("GIT_SYNC_PERMISSIONS", 0),
"the file permissions to apply to the checked-out files") "the file permissions to apply to the checked-out files")
@ -189,7 +189,7 @@ func main() {
for { for {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(*flSyncTimeout)) ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(*flSyncTimeout))
if err := syncRepo(ctx, *flRepo, *flBranch, *flRev, *flDepth, *flRoot, *flDest); err != nil { if err := syncRepo(ctx, *flRepo, *flBranch, *flRev, *flDepth, *flRoot, *flDest); err != nil {
if initialSync || (*flMaxSyncFailures >= 0 && failCount >= *flMaxSyncFailures) { if initialSync || (*flMaxSyncFailures != -1 && failCount >= *flMaxSyncFailures) {
log.Errorf("error syncing repo: %v", err) log.Errorf("error syncing repo: %v", err)
os.Exit(1) os.Exit(1)
} }