diff options
author | Sebastian Jackel <sjackel@trustinternational.com> | 2014-08-07 11:06:42 +0200 |
---|---|---|
committer | Sebastian Jackel <sjackel@trustinternational.com> | 2014-08-07 11:06:42 +0200 |
commit | 0bfbefc38a6cfdace6ede1d0c485e400898672d2 (patch) | |
tree | 4bffd56ad10e89f9e230eb8da70c71c56db520a5 /models/publickey.go | |
parent | 51abaf788c416bf48ba9e109344c5cbd41a1ef49 (diff) | |
download | gitea-0bfbefc38a6cfdace6ede1d0c485e400898672d2.tar.gz gitea-0bfbefc38a6cfdace6ede1d0c485e400898672d2.zip |
Moved defer f.Close() up so there is no chance of returning without closing and handled an error on f.Chmod
Diffstat (limited to 'models/publickey.go')
-rw-r--r-- | models/publickey.go | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/models/publickey.go b/models/publickey.go index a03d282c0a..83a3e1b87e 100644 --- a/models/publickey.go +++ b/models/publickey.go @@ -155,17 +155,19 @@ 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 } |