Skip to content

Commit

Permalink
Fix off-by-one in max-failures and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
thockin committed Jun 18, 2023
1 parent b60eef6 commit c1afd4d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ More documentation on specific topics can be [found here](./docs).
## Manual

```
GIT-SYNC
NAME
Expand Down Expand Up @@ -266,10 +265,10 @@ OPTIONS
Print this manual and exit.
--max-failures <int>, $GITSYNC_MAX_FAILURES
The number of consecutive failures allowed before aborting (the
first sync must succeed), Setting this to a negative value will
retry forever after the initial sync. If not specified, this
defaults to 0, meaning any sync failure will terminate git-sync.
The number of consecutive failures allowed before aborting.
Setting this to a negative value will retry forever. If not
specified, this defaults to 0, meaning any sync failure will
terminate git-sync.
--one-time, $GITSYNC_ONE_TIME
Exit after one sync.
Expand Down
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func main() {
"sync on receipt of the specified signal (e.g. SIGHUP)")
flMaxFailures := pflag.Int("max-failures",
envInt(0, "GITSYNC_MAX_FAILURES", "GIT_SYNC_MAX_FAILURES"),
"the number of consecutive failures allowed before aborting (the first sync must succeed, -1 will retry forever")
"the number of consecutive failures allowed before aborting (-1 will retry forever")
flTouchFile := pflag.String("touch-file",
envString("", "GITSYNC_TOUCH_FILE", "GIT_SYNC_TOUCH_FILE"),
"the path (absolute or relative to --root) to an optional file which will be touched whenever a sync completes (defaults to disabled)")
Expand Down Expand Up @@ -964,7 +964,7 @@ func main() {
if changed, hash, err := git.SyncRepo(ctx, refreshCreds); err != nil {
failCount++
updateSyncMetrics(metricKeyError, start)
if *flMaxFailures >= 0 && failCount > *flMaxFailures {
if *flMaxFailures >= 0 && failCount >= *flMaxFailures {
// Exit after too many retries, maybe the error is not recoverable.
log.Error(err, "too many failures, aborting", "failCount", failCount)
os.Exit(1)
Expand Down Expand Up @@ -2375,10 +2375,10 @@ OPTIONS
Print this manual and exit.
--max-failures <int>, $GITSYNC_MAX_FAILURES
The number of consecutive failures allowed before aborting (the
first sync must succeed), Setting this to a negative value will
retry forever after the initial sync. If not specified, this
defaults to 0, meaning any sync failure will terminate git-sync.
The number of consecutive failures allowed before aborting.
Setting this to a negative value will retry forever. If not
specified, this defaults to 0, meaning any sync failure will
terminate git-sync.
--one-time, $GITSYNC_ONE_TIME
Exit after one sync.
Expand Down
4 changes: 4 additions & 0 deletions v3-to-v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ The new name of this flag is shorter and captures the idea that any
non-recoverable error in the sync loop counts as a failure. For backwards
compatibility, `--max-sync-failures` will be used if it is specified.

git-sync v3 demanded that the first sync succeed, regardless of this flag.
git-sync v4 always allows failures up to this maximum, whether it is the first
sync or any other.

### Timeouts: `--timeout` -> `--sync-timeout`

The old `--timeout` flag took an integer number of seconds as an argument. The
Expand Down

0 comments on commit c1afd4d

Please sign in to comment.