aboutsummaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-03-22 19:17:30 +0800
committerGitHub <noreply@github.com>2024-03-22 19:17:30 +0800
commit226231ea27d4f2b0f09fa4efb39501507613b284 (patch)
treef7a45b173d4c96ff34c3fe7e7da8c73dce8a4ae3 /services
parent2f060c5834d81f0317c795fc281f9a07e03e5962 (diff)
downloadgitea-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 'services')
-rw-r--r--services/asymkey/ssh_key_authorized_principals.go9
-rw-r--r--services/doctor/authorizedkeys.go6
2 files changed, 7 insertions, 8 deletions
diff --git a/services/asymkey/ssh_key_authorized_principals.go b/services/asymkey/ssh_key_authorized_principals.go
index 822dd0ffe7..2838bb5fc7 100644
--- a/services/asymkey/ssh_key_authorized_principals.go
+++ b/services/asymkey/ssh_key_authorized_principals.go
@@ -109,6 +109,8 @@ func regeneratePrincipalKeys(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()
@@ -118,15 +120,12 @@ func regeneratePrincipalKeys(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("regeneratePrincipalKeys scan: %w", err)
}
- f.Close()
}
return nil
}
diff --git a/services/doctor/authorizedkeys.go b/services/doctor/authorizedkeys.go
index bc0266c4bc..8d6fc9cb5e 100644
--- a/services/doctor/authorizedkeys.go
+++ b/services/doctor/authorizedkeys.go
@@ -51,11 +51,11 @@ func checkAuthorizedKeys(ctx context.Context, logger log.Logger, autofix bool) e
}
linesInAuthorizedKeys.Add(line)
}
- err = scanner.Err()
- if err != nil {
+ if err = scanner.Err(); err != nil {
return fmt.Errorf("scan: %w", err)
}
- f.Close()
+ // although there is a "defer close" above, here close explicitly before the generating, because it needs to open the file for writing again
+ _ = f.Close()
// now we regenerate and check if there are any lines missing
regenerated := &bytes.Buffer{}