Skip to content

Commit 79a1a02

Browse files
committed
WIP: Allow setting autosync.interval in minutes with "m" suffix
Solves #2730
1 parent ac50558 commit 79a1a02

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

docs/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ This is a list of available options:
8484
| `audit.concurrency` | `int` | Number of concurrent audit workers. | `` |
8585
| `audit.hibp-dump-file` | `string` | Specify to a HIBPv2 Dump file (sorted) if you want `audit` to check password hashes against this file. | `None` |
8686
| `audit.hibp-use-api` | `bool` | Set to true if you want `gopass audit` to check your secrets against the public HIBPv2 API. Use with caution. This will leak a few bit of entropy. | `false` |
87-
| `autosync.interval` | `int` | AutoSync interval in days. | `3` |
87+
| `autosync.interval` | `string` | AutoSync interval in days, or minutes like "3m". | `3` |
8888
| `core.autoimport` | `bool` | Import missing keys stored in the pass repository without asking. | `false` |
8989
| `core.autopush` | `bool` | Always do a `git push` after a commit to the store. Makes sure your local changes are always available on your git remote. | `true` |
9090
| `core.autosync` | `bool` | Automatically sync (fetch & push) the git remote on an interval. | `true` |

internal/action/sync.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import (
66
"fmt"
77
"os"
88
"strconv"
9+
"strings"
910
"time"
1011

1112
"github.com/fatih/color"
13+
"github.com/gopasspw/gopass/internal/action/exit"
1214
"github.com/gopasspw/gopass/internal/backend"
1315
"github.com/gopasspw/gopass/internal/config"
1416
"github.com/gopasspw/gopass/internal/diff"
@@ -22,9 +24,11 @@ import (
2224
"github.com/urfave/cli/v2"
2325
)
2426

27+
const dayInMinutes = 24 * 60
28+
2529
var (
26-
autosyncIntervalDays = 3
27-
autosyncLastRun time.Time
30+
autosyncIntervalMinutes = 3 * dayInMinutes
31+
autosyncLastRun time.Time
2832
)
2933

3034
func init() {
@@ -40,7 +44,7 @@ func init() {
4044
return
4145
}
4246

43-
autosyncIntervalDays = iv
47+
autosyncIntervalMinutes = iv * dayInMinutes
4448
}
4549

4650
// Sync all stores with their remotes.
@@ -69,13 +73,26 @@ func (s *Action) autoSync(ctx context.Context) error {
6973

7074
ls := s.rem.LastSeen("autosync")
7175
debug.Log("autosync - last seen: %s", ls)
72-
syncInterval := autosyncIntervalDays
76+
syncInterval := autosyncIntervalMinutes
7377

7478
if s.cfg.IsSet("autosync.interval") {
75-
syncInterval = s.cfg.GetInt("autosync.interval")
79+
str := s.cfg.Get("autosync.interval")
80+
if strings.HasSuffix(str, "m") {
81+
minutes, err := strconv.Atoi(strings.TrimSuffix(str, "m"))
82+
if err != nil {
83+
return exit.Error(exit.Usage, err, "failed to parse autosync.interval %q: %q", str, err)
84+
}
85+
syncInterval = minutes
86+
} else {
87+
days, err := strconv.Atoi(str)
88+
if err != nil {
89+
return exit.Error(exit.Usage, err, "failed to parse autosync.interval %q: %q", str, err)
90+
}
91+
syncInterval = days * dayInMinutes
92+
}
7693
}
7794

78-
if time.Since(ls) > time.Duration(syncInterval)*24*time.Hour {
95+
if time.Since(ls) > time.Duration(syncInterval)*time.Minute {
7996
err := s.sync(ctx, "")
8097
if err != nil {
8198
autosyncLastRun = time.Now()

0 commit comments

Comments
 (0)