From 0de0199742f353eb66b5f80bd1cb98d74f185d7b Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Fri, 19 May 2023 15:08:05 +0200 Subject: [PATCH] Resynchronise with disk when editing tokens. We used to assume that the in-memory representation is in sync when editing a stateful token. That is usually the case, since editing requires knowing the token to edit, but resynchronising here is the right thing to do. --- token/stateful.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/token/stateful.go b/token/stateful.go index 2a3f170..854324e 100644 --- a/token/stateful.go +++ b/token/stateful.go @@ -238,6 +238,11 @@ func Edit(group, token string, expires time.Time) (*Stateful, error) { // called locked func (state *state) edit(group, token string, expires *time.Time) (*Stateful, error) { + err := state.load() + if err != nil { + return nil, err + } + if state.tokens == nil { return nil, os.ErrNotExist } @@ -257,7 +262,7 @@ func (state *state) edit(group, token string, expires *time.Time) (*Stateful, er new.Expires = expires state.tokens[token] = new } - err := state.rewrite() + err = state.rewrite() if err != nil { state.tokens[token] = old return nil, err