Skip to content

Commit

Permalink
refactor update ssh key use time (#1466)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored Apr 8, 2017
1 parent d9db188 commit 5c0bee9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 1 addition & 7 deletions cmd/serv.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,7 @@ func runServ(c *cli.Context) error {

// Update user key activity.
if keyID > 0 {
key, err := models.GetPublicKeyByID(keyID)
if err != nil {
fail("Internal error", "GetPublicKeyById: %v", err)
}

key.Updated = time.Now()
if err = models.UpdatePublicKey(key); err != nil {
if err = models.UpdatePublicKeyUpdated(keyID); err != nil {
fail("Internal error", "UpdatePublicKey: %v", err)
}
}
Expand Down
14 changes: 14 additions & 0 deletions models/ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,20 @@ func UpdatePublicKey(key *PublicKey) error {
return err
}

// UpdatePublicKeyUpdated updates public key use time.
func UpdatePublicKeyUpdated(id int64) error {
cnt, err := x.ID(id).Cols("updated").Update(&PublicKey{
Updated: time.Now(),
})
if err != nil {
return err
}
if cnt != 1 {
return ErrKeyNotExist{id}
}
return nil
}

// deletePublicKeys does the actual key deletion but does not update authorized_keys file.
func deletePublicKeys(e *xorm.Session, keyIDs ...int64) error {
if len(keyIDs) == 0 {
Expand Down

2 comments on commit 5c0bee9

@tbaschak
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I'm having issues on a freshly updated gitea as a result of this commit, it seems the UPDATE query thats generated has "SET" but no values to update, ie "SET updated="

@kubatyszko
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirming similar issue, see #1501

Please sign in to comment.