]> source.dussan.org Git - gitea.git/commitdiff
Bug fix
authorUnknown <joe2010xtmf@163.com>
Sun, 16 Mar 2014 09:48:20 +0000 (05:48 -0400)
committerUnknown <joe2010xtmf@163.com>
Sun, 16 Mar 2014 09:48:20 +0000 (05:48 -0400)
models/publickey.go

index 2f32dc3f093816ac73eafa7d8f3436ae6a19d0cf..3171e268f71b2c7f5e077439d58cf18c3bb248d7 100644 (file)
@@ -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