diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-03-22 19:17:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-22 19:17:30 +0800 |
commit | 226231ea27d4f2b0f09fa4efb39501507613b284 (patch) | |
tree | f7a45b173d4c96ff34c3fe7e7da8c73dce8a4ae3 /models/asymkey | |
parent | 2f060c5834d81f0317c795fc281f9a07e03e5962 (diff) | |
download | gitea-226231ea27d4f2b0f09fa4efb39501507613b284.tar.gz gitea-226231ea27d4f2b0f09fa4efb39501507613b284.zip |
Fix some pending problems (#29985)
These changes are quite independent and trivial, so I don't want to open
too many PRs.
* https://github.com/go-gitea/gitea/pull/29882#discussion_r1529607091
* the `f.Close` should be called properly
* the error message could be more meaningful
(https://github.com/go-gitea/gitea/pull/29882#pullrequestreview-1942557935)
*
https://github.com/go-gitea/gitea/pull/29859#pullrequestreview-1942324716
* the new translation strings don't take arguments
* https://github.com/go-gitea/gitea/pull/28710#discussion_r1443778807
* stale for long time
* #28140
* a form was forgotten to be changed to work with backend code
Diffstat (limited to 'models/asymkey')
-rw-r--r-- | models/asymkey/ssh_key_authorized_keys.go | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/models/asymkey/ssh_key_authorized_keys.go b/models/asymkey/ssh_key_authorized_keys.go index 7621994866..2e4cd62e5c 100644 --- a/models/asymkey/ssh_key_authorized_keys.go +++ b/models/asymkey/ssh_key_authorized_keys.go @@ -139,6 +139,8 @@ func RegeneratePublicKeys(ctx context.Context, t io.StringWriter) error { if err != nil { return err } + defer f.Close() + scanner := bufio.NewScanner(f) for scanner.Scan() { line := scanner.Text() @@ -148,15 +150,12 @@ func RegeneratePublicKeys(ctx context.Context, t io.StringWriter) error { } _, err = t.WriteString(line + "\n") if err != nil { - f.Close() return err } } - err = scanner.Err() - if err != nil { - return fmt.Errorf("scan: %w", err) + if err = scanner.Err(); err != nil { + return fmt.Errorf("RegeneratePublicKeys scan: %w", err) } - f.Close() } return nil } |