Skip to content

Commit

Permalink
[bugfix] Don't check for autosync on manual triggered sync (gopasspw#…
Browse files Browse the repository at this point in the history
…3026)

* [bugfix] Don't check for autosync on manual triggered sync

Fixes gopasspw#3026

Signed-off-by: Ing. Thomas Mantl <[email protected]>
  • Loading branch information
TM2500 committed Jan 6, 2025
1 parent ffe0234 commit 27bce73
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
10 changes: 7 additions & 3 deletions internal/action/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ func (s *Action) autoSync(ctx context.Context) error {
debug.Log("autosync - interval: %s", syncInterval)

if time.Since(ls) > syncInterval {
ctx = ctxutil.WithInteractive(ctx, true)
err := s.sync(ctx, "")
if err != nil {
autosyncLastRun = time.Now()
}

ctx = ctxutil.WithAutoSync(ctx, false)
return err
}

Expand Down Expand Up @@ -161,10 +163,12 @@ func (s *Action) sync(ctx context.Context, store string) error {
func (s *Action) syncMount(ctx context.Context, mp string) error {
// using GetM here to get the value for this mount, it might be different
// than the global value
if as := s.cfg.GetM(mp, "core.autosync"); as == "false" {
debug.Log("not syncing %s, autosync is disabled for this mount", mp)
if as_ctx := ctxutil.HasAutoSync(ctx); as_ctx == true {
if as := s.cfg.GetM(mp, "core.autosync"); as == "false" {
debug.Log("not syncing %s, autosync is disabled for this mount", mp)

return nil
return nil
}
}

ctxno := out.WithNewline(ctx, false)
Expand Down
15 changes: 15 additions & 0 deletions pkg/ctxutil/ctxutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
ctxKeyCommitTimestamp
ctxKeyShowParsing
ctxKeyHidden
ctxKeyAutoSync
)

// ErrNoCallback is returned when no callback is set in the context.
Expand Down Expand Up @@ -489,3 +490,17 @@ func IsHidden(ctx context.Context) bool {

return bv
}

// WithAutoSync returns a context with the autosync flag set
func WithAutoSync(ctx context.Context, autosync bool) context.Context {
return context.WithValue(ctx, ctxKeyAutoSync, autosync)
}

func HasAutoSync(ctx context.Context) bool {
bv, ok := ctx.Value(ctxKeyAutoSync).(bool)
if !ok {
return false
}

return bv
}

0 comments on commit 27bce73

Please sign in to comment.