style: run modernize -fix ./...
All checks were successful
submodules sync / sync (push) Successful in 37s
build / build (push) Successful in 2m9s
build / trigger-build-image (push) Successful in 14s

This commit is contained in:
张泊明518370910136 2025-03-25 07:34:44 -04:00
parent 8e8c018f09
commit fd583c5b7a
GPG Key ID: D47306D7062CDA9D
5 changed files with 25 additions and 35 deletions

View File

@ -16,7 +16,7 @@ type ConfStage struct {
} }
Parsers []struct { Parsers []struct {
Name string Name string
With interface{} With any
} }
} }

View File

@ -113,10 +113,7 @@ func ToRlimit(cmd stage.Cmd) ([]syscall.Rlimit, []int, error) {
if err := syscall.Getrlimit(syscall.RLIMIT_CPU, &current); err != nil { if err := syscall.Getrlimit(syscall.RLIMIT_CPU, &current); err != nil {
return nil, nil, fmt.Errorf("getrlimit RLIMIT_CPU failed: %w", err) return nil, nil, fmt.Errorf("getrlimit RLIMIT_CPU failed: %w", err)
} }
userTimeLimit := (uint64(cmd.CPULimit) + 1e9 - 1) / 1e9 // ns to s userTimeLimit := min((uint64(cmd.CPULimit)+1e9-1)/1e9, current.Max) // ns to s
if userTimeLimit > current.Max {
userTimeLimit = current.Max
}
rlimits = append(rlimits, syscall.Rlimit{ rlimits = append(rlimits, syscall.Rlimit{
Cur: userTimeLimit, Cur: userTimeLimit,
Max: current.Max, Max: current.Max,
@ -128,10 +125,7 @@ func ToRlimit(cmd stage.Cmd) ([]syscall.Rlimit, []int, error) {
if err := syscall.Getrlimit(syscall.RLIMIT_DATA, &current); err != nil { if err := syscall.Getrlimit(syscall.RLIMIT_DATA, &current); err != nil {
return nil, nil, fmt.Errorf("getrlimit RLIMIT_DATA failed: %w", err) return nil, nil, fmt.Errorf("getrlimit RLIMIT_DATA failed: %w", err)
} }
userMemLimit := cmd.MemoryLimit userMemLimit := min(cmd.MemoryLimit, current.Max)
if userMemLimit > current.Max {
userMemLimit = current.Max
}
rlimits = append(rlimits, syscall.Rlimit{ rlimits = append(rlimits, syscall.Rlimit{
Cur: userMemLimit, Cur: userMemLimit,
Max: current.Max, Max: current.Max,
@ -143,10 +137,7 @@ func ToRlimit(cmd stage.Cmd) ([]syscall.Rlimit, []int, error) {
if err := syscall.Getrlimit(syscall.RLIMIT_STACK, &current); err != nil { if err := syscall.Getrlimit(syscall.RLIMIT_STACK, &current); err != nil {
return nil, nil, fmt.Errorf("getrlimit RLIMIT_STACK failed: %w", err) return nil, nil, fmt.Errorf("getrlimit RLIMIT_STACK failed: %w", err)
} }
userStackLimit := cmd.StackLimit userStackLimit := min(cmd.StackLimit, current.Max)
if userStackLimit > current.Max {
userStackLimit = current.Max
}
rlimits = append(rlimits, syscall.Rlimit{ rlimits = append(rlimits, syscall.Rlimit{
Cur: userStackLimit, Cur: userStackLimit,
Max: current.Max, Max: current.Max,

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"log/slog" "log/slog"
"maps"
"github.com/criyle/go-judge/pb" "github.com/criyle/go-judge/pb"
"github.com/joint-online-judge/JOJ3/internal/stage" "github.com/joint-online-judge/JOJ3/internal/stage"
@ -46,9 +47,7 @@ func (e *Sandbox) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) {
} }
results := convertPBResult(pbRet.Results) results := convertPBResult(pbRet.Results)
for _, result := range results { for _, result := range results {
for fileName, fileID := range result.FileIDs { maps.Copy(e.cachedMap, result.FileIDs)
e.cachedMap[fileName] = fileID
}
} }
return results, nil return results, nil
} }

View File

@ -7,14 +7,14 @@ import (
// Referenced from https://github.com/yuriisk/clang-tidy-converter/blob/master/clang_tidy_converter/parser/clang_tidy_parser.py // Referenced from https://github.com/yuriisk/clang-tidy-converter/blob/master/clang_tidy_converter/parser/clang_tidy_parser.py
type JsonMessage struct { type JsonMessage struct {
Type string `json:"type"` Type string `json:"type"`
CheckName string `json:"checkname"` CheckName string `json:"checkname"`
Description string `json:"description"` Description string `json:"description"`
Content map[string]interface{} `json:"content"` Content map[string]any `json:"content"`
Categories []string `json:"categories"` Categories []string `json:"categories"`
Location map[string]interface{} `json:"location"` Location map[string]any `json:"location"`
Trace map[string]interface{} `json:"trace"` Trace map[string]any `json:"trace"`
Severity string `json:"severity"` Severity string `json:"severity"`
} }
func format(messages []ClangMessage) []JsonMessage { func format(messages []ClangMessage) []JsonMessage {
@ -49,7 +49,7 @@ func messagesToText(messages []ClangMessage) []string {
return textLines return textLines
} }
func extractContent(message ClangMessage) map[string]interface{} { func extractContent(message ClangMessage) map[string]any {
detailLines := "" detailLines := ""
for _, line := range message.detailsLines { for _, line := range message.detailsLines {
if line == "" { if line == "" {
@ -63,7 +63,7 @@ func extractContent(message ClangMessage) map[string]interface{} {
} }
detailLines += (line + "\n") detailLines += (line + "\n")
} }
result := map[string]interface{}{ result := map[string]any{
"body": "```\n" + detailLines + "```", "body": "```\n" + detailLines + "```",
} }
return result return result
@ -140,18 +140,18 @@ func extractCategories(message ClangMessage) []string {
return removeDuplicates(categories) return removeDuplicates(categories)
} }
func extractLocation(message ClangMessage) map[string]interface{} { func extractLocation(message ClangMessage) map[string]any {
location := map[string]interface{}{ location := map[string]any{
"path": message.filepath, "path": message.filepath,
"lines": map[string]interface{}{ "lines": map[string]any{
"begin": message.line, "begin": message.line,
}, },
} }
return location return location
} }
func extractOtherLocations(message ClangMessage) []map[string]interface{} { func extractOtherLocations(message ClangMessage) []map[string]any {
locationList := []map[string]interface{}{} locationList := []map[string]any{}
for _, child := range message.children { for _, child := range message.children {
locationList = append(locationList, extractLocation(child)) locationList = append(locationList, extractLocation(child))
locationList = append(locationList, extractOtherLocations(child)...) locationList = append(locationList, extractOtherLocations(child)...)
@ -159,8 +159,8 @@ func extractOtherLocations(message ClangMessage) []map[string]interface{} {
return locationList return locationList
} }
func extractTrace(message ClangMessage) map[string]interface{} { func extractTrace(message ClangMessage) map[string]any {
result := map[string]interface{}{ result := map[string]any{
"locations": extractOtherLocations(message), "locations": extractOtherLocations(message),
} }
return result return result

View File

@ -21,8 +21,8 @@ func (*CppCheck) parse(executorResult stage.ExecutorResult, conf Conf) stage.Par
// stdout := executorResult.Files[conf.Stdout] // stdout := executorResult.Files[conf.Stdout]
stderr := executorResult.Files[conf.Stderr] stderr := executorResult.Files[conf.Stderr]
records := make([]Record, 0) records := make([]Record, 0)
lines := strings.Split(stderr, "\n") lines := strings.SplitSeq(stderr, "\n")
for _, line := range lines { for line := range lines {
if strings.TrimSpace(line) == "" { if strings.TrimSpace(line) == "" {
continue continue
} }