Commit 0de01997 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

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.
parent 6a3b9a3b
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment