0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-11-16 15:01:07 +01:00

Merge pull request #587 from eryx/dev

Fix #266
This commit is contained in:
无闻 2014-11-17 16:17:52 -05:00
commit d21d7171b0

View file

@ -79,9 +79,9 @@ func init() {
// PublicKey represents a SSH key. // PublicKey represents a SSH key.
type PublicKey struct { type PublicKey struct {
Id int64 Id int64
OwnerId int64 `xorm:"UNIQUE(s) INDEX NOT NULL"` OwnerId int64 `xorm:"UNIQUE(s) INDEX NOT NULL"`
Name string `xorm:"UNIQUE(s) NOT NULL"` Name string `xorm:"UNIQUE(s) NOT NULL"`
Fingerprint string Fingerprint string `xorm:"INDEX NOT NULL"`
Content string `xorm:"TEXT NOT NULL"` Content string `xorm:"TEXT NOT NULL"`
Created time.Time `xorm:"CREATED"` Created time.Time `xorm:"CREATED"`
Updated time.Time Updated time.Time
@ -209,6 +209,9 @@ func AddPublicKey(key *PublicKey) (err error) {
return errors.New("not enough output for calculating fingerprint: " + stdout) return errors.New("not enough output for calculating fingerprint: " + stdout)
} }
key.Fingerprint = strings.Split(stdout, " ")[1] key.Fingerprint = strings.Split(stdout, " ")[1]
if has, err := x.Get(&PublicKey{Fingerprint: key.Fingerprint}); err == nil && has {
return ErrKeyAlreadyExist
}
// Save SSH key. // Save SSH key.
if _, err = x.Insert(key); err != nil { if _, err = x.Insert(key); err != nil {