diff --git a/cmd/go-judge/grpc_executor/grpc.go b/cmd/go-judge/grpc_executor/grpc.go index 81752a2..8947ccc 100644 --- a/cmd/go-judge/grpc_executor/grpc.go +++ b/cmd/go-judge/grpc_executor/grpc.go @@ -71,7 +71,7 @@ func (e *execServer) FileList(c context.Context, n *emptypb.Empty) (*pb.FileList func (e *execServer) FileGet(c context.Context, f *pb.FileID) (*pb.FileContent, error) { name, file := e.fs.Get(f.GetFileID()) if file == nil { - return nil, status.Errorf(codes.NotFound, "file %v not found", f.GetFileID()) + return nil, status.Errorf(codes.NotFound, "file not found: %q", f.GetFileID()) } r, err := envexec.FileToReader(file) if err != nil { @@ -111,7 +111,7 @@ func (e *execServer) FileAdd(c context.Context, fc *pb.FileContent) (*pb.FileID, func (e *execServer) FileDelete(c context.Context, f *pb.FileID) (*emptypb.Empty, error) { ok := e.fs.Remove(f.GetFileID()) if !ok { - return nil, status.Errorf(codes.NotFound, "file id does not exists for %v", f.GetFileID()) + return nil, status.Errorf(codes.NotFound, "file id does not exists: %q", f.GetFileID()) } return &emptypb.Empty{}, nil } @@ -241,10 +241,10 @@ func convertPBFile(c *pb.Request_File, srcPrefix []string) (worker.CmdFile, erro if len(srcPrefix) > 0 { ok, err := model.CheckPathPrefixes(c.Local.GetSrc(), srcPrefix) if err != nil { - return nil, err + return nil, fmt.Errorf("check path prefixes: %w", err) } if !ok { - return nil, fmt.Errorf("file (%s) does not under (%s)", c.Local.GetSrc(), srcPrefix) + return nil, fmt.Errorf("file outside of prefix: %q, %q", c.Local.GetSrc(), srcPrefix) } } return &worker.LocalFile{Src: c.Local.GetSrc()}, nil @@ -255,7 +255,7 @@ func convertPBFile(c *pb.Request_File, srcPrefix []string) (worker.CmdFile, erro case *pb.Request_File_Pipe: return &worker.Collector{Name: c.Pipe.GetName(), Max: envexec.Size(c.Pipe.GetMax()), Pipe: c.Pipe.GetPipe()}, nil } - return nil, fmt.Errorf("request file type not supported yet %v", c) + return nil, fmt.Errorf("request file type not supported: %T", c) } func convertCopyOut(copyOut []*pb.Request_CmdCopyOutFile) []worker.CmdCopyOutFile { diff --git a/cmd/go-judge/main.go b/cmd/go-judge/main.go index e96f2af..95b324c 100644 --- a/cmd/go-judge/main.go +++ b/cmd/go-judge/main.go @@ -12,7 +12,7 @@ import ( "net/http/pprof" "os" "os/signal" - "path" + "path/filepath" "runtime" "runtime/debug" "strings" @@ -465,7 +465,7 @@ func newFilsStore(conf *config.Config) (filestore.FileStore, func() error) { conf.Dir = os.TempDir() } var err error - conf.Dir = path.Join(conf.Dir, "go-judge") + conf.Dir = filepath.Join(conf.Dir, "go-judge") err = os.Mkdir(conf.Dir, os.ModePerm) if err != nil && !errors.Is(err, os.ErrExist) { logger.Fatal("Failed to create file store default dir", zap.Error(err)) diff --git a/cmd/go-judge/metrics_linux.go b/cmd/go-judge/metrics_linux.go index a801855..1ba0e5a 100644 --- a/cmd/go-judge/metrics_linux.go +++ b/cmd/go-judge/metrics_linux.go @@ -1,7 +1,7 @@ package main import ( - "path" + "path/filepath" "time" "github.com/criyle/go-judge/cmd/go-judge/config" @@ -89,7 +89,7 @@ func initCgroupMetrics(conf *config.Config, param map[string]any) { } // current cgroup is xxx/api, get the dir - prefix = path.Dir(prefix) + prefix = filepath.Dir(prefix) control, err := cgroup.GetAvailableControllerWithPrefix(prefix) if err != nil { return @@ -107,7 +107,7 @@ func initCgroupMetrics(conf *config.Config, param map[string]any) { } newCgroupMetrics(apiCg, "controller") - containersCg, err := cgroup.New(path.Join(prefix, "containers"), control) + containersCg, err := cgroup.New(filepath.Join(prefix, "containers"), control) if err != nil { return } diff --git a/cmd/go-judge/model/model.go b/cmd/go-judge/model/model.go index dfaa531..74b8446 100644 --- a/cmd/go-judge/model/model.go +++ b/cmd/go-judge/model/model.go @@ -97,6 +97,10 @@ func (s Status) MarshalJSON() ([]byte, error) { // UnmarshalJSON convert string into status func (s *Status) UnmarshalJSON(b []byte) error { str := string(b) + if len(str) < 2 || str[0] != '"' || str[len(str)-1] != '"' { + return fmt.Errorf("invalid status string: %s", str) + } + // remove quotes v, err := envexec.StringToStatus(str[1 : len(str)-1]) if err != nil { return err @@ -361,7 +365,7 @@ func convertCmdFile(f *CmdFile, srcPrefix []string) (worker.CmdFile, error) { case f.Max != nil && f.Name != nil: return &worker.Collector{Name: *f.Name, Max: envexec.Size(*f.Max), Pipe: f.Pipe}, nil default: - return nil, fmt.Errorf("file is not valid for cmd") + return nil, fmt.Errorf("file type is not valid for cmd: %v", f) } } diff --git a/cmd/go-judge/model/model_test.go b/cmd/go-judge/model/model_test.go new file mode 100644 index 0000000..c5b6322 --- /dev/null +++ b/cmd/go-judge/model/model_test.go @@ -0,0 +1,229 @@ +package model + +import ( + "encoding/json" + "os" + "path/filepath" + "testing" + "time" + + "github.com/criyle/go-judge/worker" +) + +func TestStatus_MarshalUnmarshalJSON(t *testing.T) { + type wrap struct { + Status Status `json:"status"` + } + orig := wrap{Status: 1} + data, err := json.Marshal(orig) + if err != nil { + t.Fatalf("Marshal error: %v", err) + } + var got wrap + if err := json.Unmarshal(data, &got); err != nil { + t.Fatalf("Unmarshal error: %v", err) + } + if got.Status != orig.Status { + t.Errorf("got %v, want %v", got.Status, orig.Status) + } +} + +func TestStatus_UnmarshalJSON_Invalid(t *testing.T) { + var s Status + err := s.UnmarshalJSON([]byte(`"not_a_status"`)) + if err == nil { + t.Error("expected error for invalid status string") + } +} + +func TestConvertCopyOut(t *testing.T) { + in := []string{"foo.txt", "bar.txt?"} + out := convertCopyOut(in) + if len(out) != 2 { + t.Fatalf("expected 2, got %d", len(out)) + } + if out[0].Name != "foo.txt" || out[0].Optional { + t.Errorf("unexpected: %+v", out[0]) + } + if out[1].Name != "bar.txt" || !out[1].Optional { + t.Errorf("unexpected: %+v", out[1]) + } +} + +func TestCheckPathPrefixes(t *testing.T) { + tmp := t.TempDir() + abs := filepath.Join(tmp, "file.txt") + os.WriteFile(abs, []byte("x"), 0644) + ok, err := CheckPathPrefixes(abs, []string{tmp}) + if err != nil { + t.Fatalf("CheckPathPrefixes error: %v", err) + } + if !ok { + t.Errorf("expected true for prefix match") + } + ok, err = CheckPathPrefixes(abs, []string{"/not/a/prefix"}) + if err != nil { + t.Fatalf("CheckPathPrefixes error: %v", err) + } + if ok { + t.Errorf("expected false for non-matching prefix") + } +} + +func TestConvertCmdFile_Local(t *testing.T) { + src := "/tmp/foo" + f := &CmdFile{Src: &src} + _, err := convertCmdFile(f, nil) + if err != nil { + t.Errorf("unexpected error: %v", err) + } +} + +func TestConvertCmdFile_Content(t *testing.T) { + content := "abc" + f := &CmdFile{Content: &content} + cf, err := convertCmdFile(f, nil) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + if cf == nil { + t.Error("expected non-nil CmdFile") + } +} + +func TestConvertCmdFile_FileID(t *testing.T) { + id := "id" + f := &CmdFile{FileID: &id} + cf, err := convertCmdFile(f, nil) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + if cf == nil { + t.Error("expected non-nil CmdFile") + } +} + +func TestConvertCmdFile_Collector(t *testing.T) { + name := "out" + max := int64(123) + f := &CmdFile{Name: &name, Max: &max} + cf, err := convertCmdFile(f, nil) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + if cf == nil { + t.Error("expected non-nil CmdFile") + } +} + +func TestConvertCmdFile_Invalid(t *testing.T) { + f := &CmdFile{} + _, err := convertCmdFile(f, nil) + if err == nil { + t.Error("expected error for invalid CmdFile") + } +} + +func TestResult_String(t *testing.T) { + r := Result{ + Status: 1, + ExitStatus: 0, + Error: "", + Time: uint64(time.Second), + RunTime: uint64(time.Second), + Memory: 1024, + Files: map[string]string{"foo": "bar"}, + } + s := r.String() + if s == "" { + t.Error("expected non-empty string") + } +} + +func TestConvertPipe(t *testing.T) { + p := PipeMap{ + In: PipeIndex{Index: 1, Fd: 2}, + Out: PipeIndex{Index: 3, Fd: 4}, + Name: "pipe", + Max: 100, + Proxy: true, + } + wp := convertPipe(p) + if wp.In.Index != 1 || wp.Out.Fd != 4 || wp.Name != "pipe" || wp.Limit != 100 { + t.Errorf("unexpected convertPipe result: %+v", wp) + } +} + +func TestConvertRequest_Basic(t *testing.T) { + src := "/tmp/foo" + content := "abc" + fileID := "id" + name := "out" + max := int64(123) + copyOut := []string{"result.txt", "log.txt?"} + req := &Request{ + Cmd: []Cmd{{ + Args: []string{"echo", "hello"}, + Files: []*CmdFile{{Src: &src}, {Content: &content}, {FileID: &fileID}, {Name: &name, Max: &max}}, + CopyOut: copyOut, + CPULimit: uint64(1000 * time.Millisecond), + MemoryLimit: 1024, + }}, + } + workerReq, err := ConvertRequest(req, []string{"/tmp"}) + if err != nil { + t.Fatalf("ConvertRequest error: %v", err) + } + if len(workerReq.Cmd[0].Files) != 4 { + t.Errorf("expected 4 files, got %d", len(workerReq.Cmd[0].Files)) + } + if len(workerReq.Cmd[0].CopyOut) != 2 { + t.Errorf("expected 2 copyOut, got %d", len(workerReq.Cmd[0].CopyOut)) + } + if workerReq.Cmd[0].CPULimit != 1000*time.Millisecond { + t.Errorf("unexpected CPULimit: %v", workerReq.Cmd[0].CPULimit) + } + if workerReq.Cmd[0].MemoryLimit != 1024 { + t.Errorf("unexpected MemoryLimit: %v", workerReq.Cmd[0].MemoryLimit) + } +} + +func TestConvertRequest_InvalidFile(t *testing.T) { + req := &Request{ + Cmd: []Cmd{ + { + Files: []*CmdFile{{}}, // invalid + }, + }, + } + _, err := ConvertRequest(req, nil) + if err == nil { + t.Error("expected error for invalid CmdFile") + } +} + +func TestConvertResponse_Basic(t *testing.T) { + res := worker.Response{ + Results: []worker.Result{{ + Status: 1, + ExitStatus: 0, + Error: "", + Time: 1000 * time.Millisecond, + RunTime: 900 * time.Millisecond, + Memory: 2048, + ProcPeak: 2, + Files: map[string]*os.File{}, + FileError: []worker.FileError{{Name: "foo", Type: 1, Message: "err"}}, + }}, + } + resp, _ := ConvertResponse(res, false) + if resp.Results[0].Status != 1 { + t.Errorf("unexpected Status: %v", resp.Results[0].Status) + } + if resp.Results[0].Time != uint64(1000*time.Millisecond) { + t.Errorf("unexpected Time: %v", resp.Results[0].Time) + } + if len(resp.Results[0].FileError) != 1 { + t.Errorf("unexpected FileError: %+v", resp.Results[0].FileError) + } +} diff --git a/cmd/go-judge/rest_executor/file_handler.go b/cmd/go-judge/rest_executor/file_handler.go index f7de26d..2a928ff 100644 --- a/cmd/go-judge/rest_executor/file_handler.go +++ b/cmd/go-judge/rest_executor/file_handler.go @@ -5,7 +5,7 @@ import ( "io" "mime" "net/http" - "path" + "path/filepath" "github.com/criyle/go-judge/envexec" "github.com/criyle/go-judge/filestore" @@ -82,7 +82,7 @@ func (f *fileHandle) fileIDGet(c *gin.Context) { c.AbortWithStatus(http.StatusNotFound) return } - typ := mime.TypeByExtension(path.Ext(name)) + typ := mime.TypeByExtension(filepath.Ext(name)) c.Header("Content-Type", typ) fi, ok := file.(*envexec.FileInput) // fast path diff --git a/cmd/go-judge/rest_executor/file_handler_test.go b/cmd/go-judge/rest_executor/file_handler_test.go index efc52cb..25da32d 100644 --- a/cmd/go-judge/rest_executor/file_handler_test.go +++ b/cmd/go-judge/rest_executor/file_handler_test.go @@ -2,15 +2,16 @@ package restexecutor import ( "bytes" - "github.com/criyle/go-judge/filestore" - "github.com/gin-gonic/gin" "mime/multipart" "net/http" "net/http/httptest" "os" - "path" + "path/filepath" "strings" "testing" + + "github.com/criyle/go-judge/filestore" + "github.com/gin-gonic/gin" ) func TestFilePost(t *testing.T) { @@ -65,7 +66,7 @@ func TestFilePost(t *testing.T) { fileID = fileID[1 : len(fileID)-1] // Check if the file is stored correctly - filePath := path.Join(tempDir, fileID) + filePath := filepath.Join(tempDir, fileID) _, err = os.Stat(filePath) if os.IsNotExist(err) { t.Fatalf("File should exist in the storage: %v", err) @@ -116,7 +117,7 @@ func TestFileGet(t *testing.T) { // Create files in the temporary directory for _, file := range filesToCreate { - filePath := path.Join(tempDir, file.Name) + filePath := filepath.Join(tempDir, file.Name) err := CreateFileWithContent(filePath, file.Content) if err != nil { t.Fatalf("Failed to create file: %v", err) @@ -158,7 +159,7 @@ func TestFileIDGet(t *testing.T) { // Create a test file testFileName := "test.py" - testFilePath := path.Join(tempDir, testFileName) + testFilePath := filepath.Join(tempDir, testFileName) err := CreateFileWithContent(testFilePath, "print(58 - 7 * 3)") if err != nil { t.Fatalf("Failed to create test file: %v", err) @@ -182,7 +183,7 @@ func TestFileIDGet(t *testing.T) { t.Fatalf("Expected status %d, got %d", http.StatusOK, w.Code) } - bodyBytes, err := os.ReadFile(path.Join(tempDir, fileID)) + bodyBytes, err := os.ReadFile(filepath.Join(tempDir, fileID)) if err != nil { t.Fatalf("Failed to read response body: %v", err) } @@ -206,7 +207,7 @@ func TestFileIDDelete(t *testing.T) { // Create a test file testFileName := "test.py" - testFilePath := path.Join(tempDir, testFileName) + testFilePath := filepath.Join(tempDir, testFileName) err := CreateFileWithContent(testFilePath, "print(58 - 7 * 3)") if err != nil { t.Fatalf("Failed to create test file: %v", err) @@ -231,7 +232,7 @@ func TestFileIDDelete(t *testing.T) { } // Check if the file is deleted from the storage - if _, err := os.Stat(path.Join(tempDir, fileID)); !os.IsNotExist(err) { + if _, err := os.Stat(filepath.Join(tempDir, fileID)); !os.IsNotExist(err) { t.Fatalf("Expected file to be deleted, but it still exists") } } diff --git a/cmd/go-judge/stream/file.go b/cmd/go-judge/stream/file.go index b780eaf..ddd89ae 100644 --- a/cmd/go-judge/stream/file.go +++ b/cmd/go-judge/stream/file.go @@ -12,8 +12,9 @@ import ( ) var ( - _ worker.CmdFile = &fileStreamIn{} - _ worker.CmdFile = &fileStreamOut{} + _ worker.CmdFile = &fileStreamIn{} + _ worker.CmdFile = &fileStreamOut{} + _ envexec.ReaderTTY = &fileStreamInReader{} ) type fileStreamIn struct { diff --git a/cmd/go-judge/ws_executor/websocket.go b/cmd/go-judge/ws_executor/websocket.go index 4257d00..736f804 100644 --- a/cmd/go-judge/ws_executor/websocket.go +++ b/cmd/go-judge/ws_executor/websocket.go @@ -77,7 +77,7 @@ func (h *wsHandle) handleWS(c *gin.Context) { } r, err := model.ConvertRequest(&req.Request, h.srcPrefix) if err != nil { - return fmt.Errorf("ws convert error: %v", err) + return fmt.Errorf("ws convert error: %w", err) } ctx, cancel := context.WithCancel(baseCtx) @@ -90,7 +90,7 @@ func (h *wsHandle) handleWS(c *gin.Context) { }: } cancel() - h.logger.Debug("ws request error: %v", zap.Error(err)) + h.logger.Debug("ws request error", zap.Error(err)) return nil } @@ -171,7 +171,7 @@ func (h *wsHandle) handleWS(c *gin.Context) { case r := <-resultCh: conn.SetWriteDeadline(time.Now().Add(writeWait)) if err := conn.WriteJSON(r); err != nil { - h.logger.Info("ws write error:", zap.Error(err)) + h.logger.Info("ws write error", zap.Error(err)) return } case <-ticker.C: @@ -224,7 +224,7 @@ func (c *contextMap) Add(reqID string, cancel context.CancelFunc) error { defer c.mu.Unlock() if _, exist := c.m[reqID]; exist { - return fmt.Errorf("duplicated request id: %v", reqID) + return fmt.Errorf("duplicated request id: %q", reqID) } c.m[reqID] = cancel return nil diff --git a/env/macsandbox/environment_darwin.go b/env/macsandbox/environment_darwin.go index 890f868..8cceb48 100644 --- a/env/macsandbox/environment_darwin.go +++ b/env/macsandbox/environment_darwin.go @@ -3,7 +3,7 @@ package macsandbox import ( "context" "os" - "path" + "path/filepath" "syscall" "time" @@ -137,15 +137,15 @@ func (e *environment) WorkDir() *os.File { } func (e *environment) Open(p string, flags int, perm os.FileMode) (*os.File, error) { - return os.OpenFile(path.Join(e.wdPath, p), flags, perm) + return os.OpenFile(filepath.Join(e.wdPath, p), flags, perm) } func (e *environment) MkdirAll(p string, perm os.FileMode) error { - return os.MkdirAll(path.Join(e.wdPath, p), perm) + return os.MkdirAll(filepath.Join(e.wdPath, p), perm) } func (e *environment) Symlink(oldName, newName string) error { - return os.Symlink(oldName, path.Join(e.wdPath, newName)) + return os.Symlink(oldName, filepath.Join(e.wdPath, newName)) } func (e *environment) Destroy() error { @@ -171,7 +171,7 @@ func removeContents(dir string) error { } for _, name := range names { - err = os.RemoveAll(path.Join(dir, name)) + err = os.RemoveAll(filepath.Join(dir, name)) if err != nil { return err } diff --git a/env/mount_linux.go b/env/mount_linux.go index d4c2bfe..6b39550 100644 --- a/env/mount_linux.go +++ b/env/mount_linux.go @@ -3,7 +3,7 @@ package env import ( "fmt" "os" - "path" + "path/filepath" "github.com/criyle/go-sandbox/container" "github.com/criyle/go-sandbox/pkg/mount" @@ -61,12 +61,12 @@ func parseMountConfig(m *Mounts) (*mount.Builder, error) { } for _, mt := range m.Mount { target := mt.Target - if path.IsAbs(target) { - target = path.Clean(target[1:]) + if filepath.IsAbs(target) { + target = filepath.Clean(target[1:]) } source := mt.Source - if !path.IsAbs(source) { - source = path.Join(wd, source) + if !filepath.IsAbs(source) { + source = filepath.Join(wd, source) } switch mt.Type { case "bind": diff --git a/env/winc/environment_windows.go b/env/winc/environment_windows.go index a14ed6b..6246d1a 100644 --- a/env/winc/environment_windows.go +++ b/env/winc/environment_windows.go @@ -7,7 +7,7 @@ import ( "errors" "fmt" "os" - "path" + "path/filepath" "syscall" "time" "unicode/utf16" @@ -286,15 +286,15 @@ func (e *Environment) WorkDir() *os.File { // Open opens file related to root func (e *Environment) Open(p string, flags int, perm os.FileMode) (*os.File, error) { - return os.OpenFile(path.Join(e.root, p), flags, perm) + return os.OpenFile(filepath.Join(e.root, p), flags, perm) } func (e *Environment) MkdirAll(p string, perm os.FileMode) error { - return os.MkdirAll(path.Join(e.root, p), perm) + return os.MkdirAll(filepath.Join(e.root, p), perm) } func (e *Environment) Symlink(oldName, newName string) error { - return os.Symlink(oldName, path.Join(e.root, newName)) + return os.Symlink(oldName, filepath.Join(e.root, newName)) } // Destroy destroys the environment @@ -327,7 +327,7 @@ func removeContents(dir string) error { } for _, name := range names { - err = os.RemoveAll(path.Join(dir, name)) + err = os.RemoveAll(filepath.Join(dir, name)) if err != nil { return err } diff --git a/envexec/file_util_others.go b/envexec/file_util_others.go index 6f67f18..6c4f75f 100644 --- a/envexec/file_util_others.go +++ b/envexec/file_util_others.go @@ -6,7 +6,7 @@ import ( "fmt" "io" "os" - "path" + "path/filepath" ) func readerToFile(reader io.Reader) (*os.File, error) { @@ -49,13 +49,13 @@ func copyDir(src *os.File, dst string) error { } func copyDirFile(src, dst, name string) error { - s, err := os.Open(path.Join(src, name)) + s, err := os.Open(filepath.Join(src, name)) if err != nil { return err } defer s.Close() - t, err := os.OpenFile(path.Join(dst, name), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0777) + t, err := os.OpenFile(filepath.Join(dst, name), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0777) if err != nil { return err } diff --git a/filestore/file_local.go b/filestore/file_local.go index ca6e230..aa7471c 100644 --- a/filestore/file_local.go +++ b/filestore/file_local.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "os" - "path" "path/filepath" "sync" @@ -41,7 +40,7 @@ func (s *fileLocalStore) Get(id string) (string, envexec.File) { s.mu.RLock() defer s.mu.RUnlock() - p := path.Join(s.dir, id) + p := filepath.Join(s.dir, id) if _, err := os.Stat(p); os.IsNotExist(err) { return "", nil } @@ -57,7 +56,7 @@ func (s *fileLocalStore) Remove(id string) bool { defer s.mu.Unlock() delete(s.name, id) - p := path.Join(s.dir, id) + p := filepath.Join(s.dir, id) if _, err := os.Stat(p); os.IsNotExist(err) { return false } @@ -87,7 +86,7 @@ func (s *fileLocalStore) New() (*os.File, error) { if err != nil { return nil, err } - f, err := os.OpenFile(path.Join(s.dir, id), os.O_CREATE|os.O_RDWR|os.O_EXCL, 0644) + f, err := os.OpenFile(filepath.Join(s.dir, id), os.O_CREATE|os.O_RDWR|os.O_EXCL, 0644) if err == nil { return f, nil } diff --git a/go.mod b/go.mod index 37527cb..1c802cf 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/coreos/go-systemd/v22 v22.5.0 github.com/creack/pty v1.1.24 github.com/criyle/go-judge/pb v1.0.0 - github.com/criyle/go-sandbox v0.11.4 + github.com/criyle/go-sandbox v0.11.5 github.com/elastic/go-seccomp-bpf v1.5.0 github.com/elastic/go-ucfg v0.8.8 github.com/gin-contrib/zap v1.1.5 diff --git a/go.sum b/go.sum index 3581ebf..ebfb00d 100644 --- a/go.sum +++ b/go.sum @@ -20,8 +20,8 @@ github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s= github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE= github.com/criyle/go-judge/pb v1.0.0 h1:8A4zHPPCGCDTuFY1GW5Hqpg+8ETIwzgXxiRpYKKb2zA= github.com/criyle/go-judge/pb v1.0.0/go.mod h1:hjgixgK9NH9ktwc29xbXVdZDOlKfEkRkEbZ4W5bOMmw= -github.com/criyle/go-sandbox v0.11.4 h1:cbah7BvabMGHUDUOEe6iww7YA3dHYqGYumXYhO6bsAI= -github.com/criyle/go-sandbox v0.11.4/go.mod h1:nfsXyZ2s0oQYV0je1fp5SJ7XrKTx5WQ4g5nl4SsFB/E= +github.com/criyle/go-sandbox v0.11.5 h1:yT6nWRIPcCdRDXvFItaJEn2tR00DUrgXVIvKPM2cHog= +github.com/criyle/go-sandbox v0.11.5/go.mod h1:nfsXyZ2s0oQYV0je1fp5SJ7XrKTx5WQ4g5nl4SsFB/E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/worker/file.go b/worker/file.go index 9aae9cd..c17819d 100644 --- a/worker/file.go +++ b/worker/file.go @@ -60,7 +60,7 @@ type CachedFile struct { func (f *CachedFile) EnvFile(fs filestore.FileStore) (envexec.File, error) { _, fd := fs.Get(f.FileID) if fd == nil { - return nil, fmt.Errorf("file not exists with id %v", f.FileID) + return nil, fmt.Errorf("file does not exists with id: %q", f.FileID) } return fd, nil } diff --git a/worker/waiter.go b/worker/waiter.go index 4347cdb..1ac3ef9 100644 --- a/worker/waiter.go +++ b/worker/waiter.go @@ -17,8 +17,10 @@ type waiter struct { } func (w *waiter) Wait(ctx context.Context, u envexec.Process) bool { - if w.clockTimeLimit < w.timeLimit { - w.clockTimeLimit = w.timeLimit + clockTimeLimit := w.clockTimeLimit + timeLimit := w.timeLimit + if clockTimeLimit < w.timeLimit { + clockTimeLimit = w.timeLimit } start := time.Now() @@ -40,11 +42,11 @@ func (w *waiter) Wait(ctx context.Context, u envexec.Process) bool { return false case <-ticker.C: - if time.Since(start) > w.clockTimeLimit { + if time.Since(start) > clockTimeLimit { return true } u := u.Usage() - if u.Time > w.timeLimit { + if u.Time > timeLimit { return true } } diff --git a/worker/worker.go b/worker/worker.go index 1e80d72..4f8ea13 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -4,7 +4,7 @@ import ( "context" "fmt" "os" - "path" + "path/filepath" "sync" "sync/atomic" "time" @@ -347,10 +347,10 @@ func (w *worker) prepareCmd(rc Cmd, pipeFileName map[string]bool) (*envexec.Cmd, var copyOutDir string if rc.CopyOutDir != "" { - if path.IsAbs(rc.CopyOutDir) { + if filepath.IsAbs(rc.CopyOutDir) { copyOutDir = rc.CopyOutDir } else { - copyOutDir = path.Join(w.workDir, rc.CopyOutDir) + copyOutDir = filepath.Join(w.workDir, rc.CopyOutDir) } }