summaryrefslogtreecommitdiffstats
path: root/models/publickey.go
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-03-16 05:48:20 -0400
committerUnknown <joe2010xtmf@163.com>2014-03-16 05:48:20 -0400
commitbcafba47e8c384a13315d998eb1ba17e9aaf16f9 (patch)
treeb4ffc60fb7e22f507969e82dc92702664c999586 /models/publickey.go
parentab747f279088c9ed6114c4227c71173ebd1e6f00 (diff)
downloadgitea-bcafba47e8c384a13315d998eb1ba17e9aaf16f9.tar.gz
gitea-bcafba47e8c384a13315d998eb1ba17e9aaf16f9.zip
Bug fix
Diffstat (limited to 'models/publickey.go')
-rw-r--r--models/publickey.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/models/publickey.go b/models/publickey.go
index 2f32dc3f09..3171e268f7 100644
--- a/models/publickey.go
+++ b/models/publickey.go
@@ -6,6 +6,7 @@ package models
import (
"bufio"
+ "errors"
"fmt"
"io"
"os"
@@ -88,6 +89,12 @@ func AddPublicKey(key *PublicKey) error {
// DeletePublicKey deletes SSH key information both in database and authorized_keys file.
func DeletePublicKey(key *PublicKey) (err error) {
+ has, err := orm.Id(key.Id).Get(key)
+ if err != nil {
+ return err
+ } else if !has {
+ return errors.New("Public key does not exist")
+ }
if _, err = orm.Delete(key); err != nil {
return err
}
@@ -128,12 +135,8 @@ func DeletePublicKey(key *PublicKey) (err error) {
// Found the line and copy rest of file.
if strings.Contains(line, key.Content) {
- if _, err = io.Copy(fw, fr); err != nil {
- return err
- }
- break
+ continue
}
-
// Still finding the line, copy the line that currently read.
if _, err = fw.WriteString(line + "\n"); err != nil {
return err