diff --git a/internal/executors/sandbox/executor.go b/internal/executors/sandbox/executor.go index d8cbd08..edadfa1 100644 --- a/internal/executors/sandbox/executor.go +++ b/internal/executors/sandbox/executor.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "log/slog" + "os" + "path/filepath" "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" "github.com/criyle/go-judge/pb" @@ -24,6 +26,25 @@ func (e *Sandbox) Run(cmd stage.Cmd) (*stage.Result, error) { cmd.CopyIn[k] = stage.CmdFile{FileID: &fileID} } } + if cmd.CopyInCwd { + err := filepath.Walk(".", + func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + absPath, err := filepath.Abs(path) + if err != nil { + return err + } + if !info.IsDir() { + cmd.CopyIn[path] = stage.CmdFile{Src: &absPath} + } + return nil + }) + if err != nil { + return nil, err + } + } req := &pb.Request{Cmd: convertPBCmd([]stage.Cmd{cmd})} ret, err := e.execClient.Exec(context.TODO(), req) if err != nil { diff --git a/internal/stage/model.go b/internal/stage/model.go index 78997b3..3da0242 100644 --- a/internal/stage/model.go +++ b/internal/stage/model.go @@ -45,6 +45,7 @@ type Cmd struct { CopyIn map[string]CmdFile `json:"copyIn"` CopyInCached map[string]string `json:"copyInCached"` + CopyInCwd bool `json:"copyInCwd"` CopyOut []string `json:"copyOut"` CopyOutCached []string `json:"copyOutCached"`