From 21e82793701085f0ce355dfd7a6e5d3043b4c51f Mon Sep 17 00:00:00 2001 From: Eryx Date: Mon, 27 Oct 2014 15:30:41 +0800 Subject: [PATCH] Fix #266 --- models/publickey.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/models/publickey.go b/models/publickey.go index 762d7333f..3f843ee29 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, _ := x.Get(&PublicKey{Fingerprint: key.Fingerprint}); has { + return ErrKeyAlreadyExist + } // Save SSH key. if _, err = x.Insert(key); err != nil {