From 621142316541182b32b2072106fb8112d5405b03 Mon Sep 17 00:00:00 2001 From: BoYanZh Date: Thu, 26 Jun 2025 02:20:03 -0400 Subject: [PATCH] feat: support -copy-in-dir for easier debugging (#155) * feat: support -copy-in-dir for easier debugging * fix: use relative path --- cmd/go-judge-shell/shell.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cmd/go-judge-shell/shell.go b/cmd/go-judge-shell/shell.go index 5628212..dd9dd25 100644 --- a/cmd/go-judge-shell/shell.go +++ b/cmd/go-judge-shell/shell.go @@ -7,6 +7,7 @@ import ( "log" "os" "os/signal" + "path/filepath" "syscall" "time" @@ -19,6 +20,7 @@ var ( transport = flag.String("transport", "websocket", "defines transport layer (websocket / grpc)") wsURL = flag.String("ws-url", "ws://localhost:5050/stream", "HTTP server url") grpcAddr = flag.String("grpc-addr", "localhost:5051", "GRPC server addr") + copyInDir = flag.String("copy-in-dir", "", "directory to copy files from") ) const ( @@ -61,6 +63,27 @@ func main() { } func run(sc Stream, args []string) (*model.Response, error) { + copyIn := make(map[string]model.CmdFile, 0) + if *copyInDir != "" { + _ = filepath.Walk(*copyInDir, + func(path string, info os.FileInfo, err error) error { + if err != nil { + return nil + } + absPath, err := filepath.Abs(path) + if err != nil { + return nil + } + relPath, err := filepath.Rel(*copyInDir, path) + if err != nil { + return nil + } + if !info.IsDir() { + copyIn[relPath] = model.CmdFile{Src: &absPath} + } + return nil + }) + } req := model.Request{ Cmd: []model.Cmd{{ Args: args, @@ -70,6 +93,7 @@ func run(sc Stream, args []string) (*model.Response, error) { {StreamOut: true}, {StreamOut: true}, }, + CopyIn: copyIn, CPULimit: uint64(cpuLimit.Nanoseconds()), ClockLimit: uint64(sessionLimit.Nanoseconds()), MemoryLimit: memoryLimit,