fix: stop discarding file close and test setup errors (#39987)

- Fix
https://github.com/go-gitea/gitea/security/quality/rules/go%2Funhandled-writable-file-close,
ignored close errors hide failed flushes, which could lose rotated logs
and truncate authorized_keys
- Fix `TestProjects` fixture reset, from
https://github.com/go-gitea/gitea/security/quality/ai-findings,
`TruncateBeans` rejected the table names and the ignored error let the
test run against fixture data
This commit is contained in:
silverwind
2026-11-06 20:45:17 +00:00
committed by GitHub
parent 24700dca2a
commit ede9ec3e10
9 changed files with 32 additions and 34 deletions

View File

@@ -6,6 +6,7 @@ package asymkey
import (
"bufio"
"context"
"errors"
"fmt"
"io"
"os"
@@ -107,7 +108,7 @@ func writeAuthorizedStringForKey(key *PublicKey, w io.Writer) (keyValid bool, er
}
// appendAuthorizedKeysToFile appends new SSH keys' content to authorized_keys file.
func appendAuthorizedKeysToFile(keys ...*PublicKey) error {
func appendAuthorizedKeysToFile(keys ...*PublicKey) (err error) {
// Don't need to rewrite this file if builtin SSH server is enabled.
if setting.SSH.StartBuiltinServer || !setting.SSH.CreateAuthorizedKeysFile {
return nil
@@ -133,7 +134,7 @@ func appendAuthorizedKeysToFile(keys ...*PublicKey) error {
if err != nil {
return err
}
defer f.Close()
defer func() { err = errors.Join(err, f.Close()) }()
// Note: chmod command does not support in Windows.
if !consts.IsWindows {