feat: support copy cwd to sandbox (#13)

This commit is contained in:
张泊明518370910136 2024-03-04 01:47:51 -05:00
parent 1f20aa3105
commit 4441012e0d
GPG Key ID: D47306D7062CDA9D
2 changed files with 22 additions and 0 deletions

View File

@ -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 {

View File

@ -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"`