File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -496,16 +496,21 @@ func UpdatePublicKey(key *PublicKey) error {
496496// UpdatePublicKeyUpdated updates public key use time.
497497func UpdatePublicKeyUpdated (id int64 ) error {
498498 now := time .Now ()
499- cnt , err := x .ID (id ).Cols ("updated_unix" ).Update (& PublicKey {
499+ // Check if key exists before update as affected rows count is unreliable
500+ // and will return 0 affected rows if two updates are made at the same time
501+ if cnt , err := x .ID (id ).Count (& PublicKey {}); err != nil {
502+ return err
503+ } else if cnt != 1 {
504+ return ErrKeyNotExist {id }
505+ }
506+
507+ _ , err := x .ID (id ).Cols ("updated_unix" ).Update (& PublicKey {
500508 Updated : now ,
501509 UpdatedUnix : now .Unix (),
502510 })
503511 if err != nil {
504512 return err
505513 }
506- if cnt != 1 {
507- return ErrKeyNotExist {id }
508- }
509514 return nil
510515}
511516
You can’t perform that action at this time.
0 commit comments