Bug fix
This commit is contained in:
parent
ab747f2790
commit
bcafba47e8
1 changed files with 8 additions and 5 deletions
|
@ -6,6 +6,7 @@ package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
@ -88,6 +89,12 @@ func AddPublicKey(key *PublicKey) error {
|
||||||
|
|
||||||
// DeletePublicKey deletes SSH key information both in database and authorized_keys file.
|
// DeletePublicKey deletes SSH key information both in database and authorized_keys file.
|
||||||
func DeletePublicKey(key *PublicKey) (err error) {
|
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 {
|
if _, err = orm.Delete(key); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -128,12 +135,8 @@ func DeletePublicKey(key *PublicKey) (err error) {
|
||||||
|
|
||||||
// Found the line and copy rest of file.
|
// Found the line and copy rest of file.
|
||||||
if strings.Contains(line, key.Content) {
|
if strings.Contains(line, key.Content) {
|
||||||
if _, err = io.Copy(fw, fr); err != nil {
|
continue
|
||||||
return err
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Still finding the line, copy the line that currently read.
|
// Still finding the line, copy the line that currently read.
|
||||||
if _, err = fw.WriteString(line + "\n"); err != nil {
|
if _, err = fw.WriteString(line + "\n"); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue