feat: support copy cwd to sandbox (#13)
This commit is contained in:
parent
1f20aa3105
commit
4441012e0d
|
@ -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 {
|
||||
|
|
|
@ -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"`
|
||||
|
|
Loading…
Reference in New Issue
Block a user