fix(ci): 修正分布式实现的 staticcheck 错误

迁移 CLI 不再遮蔽 BeginMigration 的错误,拒绝启动时正确返回失败。规范节点批准错误文案和归档 HTTP 状态常量;tar.Reader 已将旧普通文件类型归一化,无需引用已弃用常量。

验证:CI 固定版本 staticcheck 全量通过;cmd/felis、archivetransfer、backup、distributed 的 go test -race 通过。
This commit is contained in:
Lemon-miaow committed 2026-10-01 20:06:08 +08:00
1 parent b01aae77a2
commit 109701a276
4 files changed
+15 -15

No files matched your search

+2 -2
View File
@@ -275,7 +275,7 @@ func approveNode(ctx context.Context, cl client.Client, cs kubernetes.Interface,
for _, endpoint := range endpoints { for _, endpoint := range endpoints {
c, err := net.DialTimeout("tcp", endpoint, 5*time.Second) c, err := net.DialTimeout("tcp", endpoint, 5*time.Second)
if err != nil { if err != nil {
return fmt.Errorf("Velocity host cannot dial backend Service %s: %w", endpoint, err) return fmt.Errorf("velocity host cannot dial backend Service %s: %w", endpoint, err)
} }
c.Close() c.Close()
} }
@@ -321,7 +321,7 @@ func approveNode(ctx context.Context, cl client.Client, cs kubernetes.Interface,
return err return err
} }
if len(game.Spec.Ingress) == 0 { if len(game.Spec.Ingress) == 0 {
return fmt.Errorf("Velocity ingress policy is not configured") return fmt.Errorf("velocity ingress policy is not configured")
} }
prevGame := game.DeepCopy() prevGame := game.DeepCopy()
for _, cidr := range observed { for _, cidr := range observed {
+7 -7
View File
@@ -76,19 +76,19 @@ func cmdServerMigrate(args []string, stdout, stderr io.Writer) int {
var op distributed.Operation var op distributed.Operation
switch args[0] { switch args[0] {
case "start": case "start":
host, err := config.Load(*cfgPath) host, cfgErr := config.Load(*cfgPath)
if err != nil { if cfgErr != nil {
fmt.Fprintln(stderr, err) fmt.Fprintln(stderr, cfgErr)
return 1 return 1
} }
drv, err := openPodStore(ctx, host.Database.URL, "migration", stderr) drv, dbErr := openPodStore(ctx, host.Database.URL, "migration", stderr)
if err != nil { if dbErr != nil {
fmt.Fprintln(stderr, err) fmt.Fprintln(stderr, dbErr)
return 1 return 1
} }
defer drv.Close() defer drv.Close()
var owner sql.NullString var owner sql.NullString
if err = drv.DB().QueryRowContext(ctx, "SELECT owner_id FROM servers WHERE name=$1 AND deleted_at IS NULL AND retire_requested_at IS NULL", *name).Scan(&owner); err != nil { if err := drv.DB().QueryRowContext(ctx, "SELECT owner_id FROM servers WHERE name=$1 AND deleted_at IS NULL AND retire_requested_at IS NULL", *name).Scan(&owner); err != nil {
fmt.Fprintln(stderr, err) fmt.Fprintln(stderr, err)
return 1 return 1
} }
+5 -5
View File
@@ -129,7 +129,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
if r.URL.Path == "/archives" && r.Method == http.MethodDelete { if r.URL.Path == "/archives" && r.Method == http.MethodDelete {
if len(s.Key) < 32 || !hmac.Equal([]byte(strings.TrimPrefix(r.Header.Get("Authorization"), "Bearer ")), []byte(s.Key)) { if len(s.Key) < 32 || !hmac.Equal([]byte(strings.TrimPrefix(r.Header.Get("Authorization"), "Bearer ")), []byte(s.Key)) {
http.Error(w, "unauthorized", 401) http.Error(w, "unauthorized", http.StatusUnauthorized)
return return
} }
var q struct { var q struct {
@@ -152,7 +152,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
if r.URL.Path == "/inspect" && r.Method == http.MethodPost { if r.URL.Path == "/inspect" && r.Method == http.MethodPost {
if len(s.Key) < 32 || !hmac.Equal([]byte(strings.TrimPrefix(r.Header.Get("Authorization"), "Bearer ")), []byte(s.Key)) { if len(s.Key) < 32 || !hmac.Equal([]byte(strings.TrimPrefix(r.Header.Get("Authorization"), "Bearer ")), []byte(s.Key)) {
http.Error(w, "unauthorized", 401) http.Error(w, "unauthorized", http.StatusUnauthorized)
return return
} }
var q struct { var q struct {
@@ -165,7 +165,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
local := &backup.TarLocal{BackupRoot: s.Root} local := &backup.TarLocal{BackupRoot: s.Root}
sum, err := local.Verify(r.Context(), backup.ArchiveRef(q.Ref), "") sum, err := local.Verify(r.Context(), backup.ArchiveRef(q.Ref), "")
if err != nil { if err != nil {
http.Error(w, "archive is absent or corrupt", 422) http.Error(w, "archive is absent or corrupt", http.StatusUnprocessableEntity)
return return
} }
st, err := os.Stat(q.Ref) st, err := os.Stat(q.Ref)
@@ -347,7 +347,7 @@ func (s *Server) upload(r *http.Request, t Ticket) error {
func (s *Server) download(w http.ResponseWriter, r *http.Request, t Ticket) { func (s *Server) download(w http.ResponseWriter, r *http.Request, t Ticket) {
root, err := os.OpenRoot(s.Root) root, err := os.OpenRoot(s.Root)
if err != nil { if err != nil {
http.Error(w, "archive unavailable", 503) http.Error(w, "archive unavailable", http.StatusServiceUnavailable)
return return
} }
defer root.Close() defer root.Close()
@@ -359,7 +359,7 @@ func (s *Server) download(w http.ResponseWriter, r *http.Request, t Ticket) {
defer f.Close() defer f.Close()
st, err := f.Stat() st, err := f.Stat()
if err != nil || !st.Mode().IsRegular() || st.Size() > t.Limit { if err != nil || !st.Mode().IsRegular() || st.Size() > t.Limit {
http.Error(w, "archive exceeds transfer bounds", 413) http.Error(w, "archive exceeds transfer bounds", http.StatusRequestEntityTooLarge)
return return
} }
w.Header().Set("Content-Type", "application/gzip") w.Header().Set("Content-Type", "application/gzip")
+1 -1
View File
@@ -41,7 +41,7 @@ func VerifyRestored(ctx context.Context, ref, world string) error {
if err != nil { if err != nil {
return err return err
} }
if h.Typeflag != tar.TypeReg && h.Typeflag != tar.TypeRegA { if h.Typeflag != tar.TypeReg {
continue continue
} }
dst, err := root.Open(h.Name) dst, err := root.Open(h.Name)