1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-22 08:42:32 -05:00

Moved defer f.Close() up so there is no chance of returning without closing and handled an error on f.Chmod

This commit is contained in:
Sebastian Jackel 2014-08-07 11:06:42 +02:00
parent 51abaf788c
commit 0bfbefc38a

View file

@ -155,16 +155,18 @@ func saveAuthorizedKeyFile(key *PublicKey) error {
if err != nil {
return err
}
defer f.Close()
finfo, err := f.Stat()
if err != nil {
return err
}
if finfo.Mode().Perm() > 0600 {
log.Error(3, "authorized_keys file has unusual permission flags: %s - setting to -rw-------", finfo.Mode().Perm().String())
f.Chmod(0600)
err = f.Chmod(0600)
if err != nil {
return err
}
}
defer f.Close()
_, err = f.WriteString(key.GetAuthorizedString())
return err