summaryrefslogtreecommitdiffstats
path: root/models/publickey.go
diff options
context:
space:
mode:
author无闻 <joe2010xtmf@163.com>2014-11-17 16:17:52 -0500
committer无闻 <joe2010xtmf@163.com>2014-11-17 16:17:52 -0500
commitd21d7171b06eda64c0475431a39438c70047f9cf (patch)
tree031e396053663855eec026b01ed45011685b55d8 /models/publickey.go
parent32dcaefafa6039e8fe27d263290e33ce5e5d3aa5 (diff)
parente84e0ab904e076e248d7b84c0a840b5473c6739b (diff)
downloadgitea-d21d7171b06eda64c0475431a39438c70047f9cf.tar.gz
gitea-d21d7171b06eda64c0475431a39438c70047f9cf.zip
Merge pull request #587 from eryx/dev
Fix #266
Diffstat (limited to 'models/publickey.go')
-rw-r--r--models/publickey.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/models/publickey.go b/models/publickey.go
index f5e487fdbb..f379e12188 100644
--- a/models/publickey.go
+++ b/models/publickey.go
@@ -79,9 +79,9 @@ func init() {
// PublicKey represents a SSH key.
type PublicKey struct {
Id int64
- OwnerId int64 `xorm:"UNIQUE(s) INDEX NOT NULL"`
- Name string `xorm:"UNIQUE(s) NOT NULL"`
- Fingerprint string
+ OwnerId int64 `xorm:"UNIQUE(s) INDEX NOT NULL"`
+ Name string `xorm:"UNIQUE(s) NOT NULL"`
+ Fingerprint string `xorm:"INDEX NOT NULL"`
Content string `xorm:"TEXT NOT NULL"`
Created time.Time `xorm:"CREATED"`
Updated time.Time
@@ -209,6 +209,9 @@ func AddPublicKey(key *PublicKey) (err error) {
return errors.New("not enough output for calculating fingerprint: " + stdout)
}
key.Fingerprint = strings.Split(stdout, " ")[1]
+ if has, err := x.Get(&PublicKey{Fingerprint: key.Fingerprint}); err == nil && has {
+ return ErrKeyAlreadyExist
+ }
// Save SSH key.
if _, err = x.Insert(key); err != nil {