From 5c1538888254c7683630783e29edc76f1d9c13d3 Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Tue, 5 Mar 2024 02:02:05 -0500 Subject: [PATCH] refactor: rename files -> stdin, stdout, stderr --- _example/simple/conf.toml | 18 +++++++++--------- cmd/joj3/conf.go | 8 +++++--- internal/executors/sandbox/convert.go | 2 +- internal/stage/model.go | 8 +++++--- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/_example/simple/conf.toml b/_example/simple/conf.toml index d8c0580..e70ab47 100644 --- a/_example/simple/conf.toml +++ b/_example/simple/conf.toml @@ -12,12 +12,12 @@ procLimit = 50 copyInCwd = true copyOut = ["stdout", "stderr"] copyOutCached = ["a"] -[[stages.executor.with.default.files]] +[stages.executor.with.default.stdin] content = "" -[[stages.executor.with.default.files]] +[stages.executor.with.default.stdout] name = "stdout" max = 4_096 -[[stages.executor.with.default.files]] +[stages.executor.with.default.stderr] name = "stderr" max = 4_096 [stages.parser] @@ -39,21 +39,21 @@ copyOut = ["stdout", "stderr"] [stages.executor.with.default.copyInCached] a = "a" [[stages.executor.with.cases]] -[[stages.executor.with.cases.files]] +[stages.executor.with.cases.stdin] src = "1.stdin" -[[stages.executor.with.cases.files]] +[stages.executor.with.cases.stdout] name = "stdout" max = 4_096 -[[stages.executor.with.cases.files]] +[stages.executor.with.cases.stderr] name = "stderr" max = 4_096 [[stages.executor.with.cases]] -[[stages.executor.with.cases.files]] +[stages.executor.with.cases.stdin] src = "2.stdin" -[[stages.executor.with.cases.files]] +[stages.executor.with.cases.stdout] name = "stdout" max = 4_096 -[[stages.executor.with.cases.files]] +[stages.executor.with.cases.stderr] name = "stderr" max = 4_096 [stages.parser] diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index edd9b08..aca580c 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -22,9 +22,11 @@ type Conf struct { } type OptionalCmd struct { - Args *[]string - Env *[]string - Files *[]*stage.CmdFile + Args *[]string + Env *[]string + Stdin *stage.CmdFile + Stdout *stage.CmdFile + Stderr *stage.CmdFile CPULimit *uint64 RealCPULimit *uint64 diff --git a/internal/executors/sandbox/convert.go b/internal/executors/sandbox/convert.go index b61fe0e..e5b786f 100644 --- a/internal/executors/sandbox/convert.go +++ b/internal/executors/sandbox/convert.go @@ -17,7 +17,7 @@ func convertPBCmd(cmd []stage.Cmd) []*pb.Request_CmdType { Args: c.Args, Env: c.Env, Tty: c.TTY, - Files: convertPBFiles(c.Files), + Files: convertPBFiles([]*stage.CmdFile{c.Stdin, c.Stdout, c.Stderr}), CpuTimeLimit: c.CPULimit, ClockTimeLimit: c.ClockLimit, MemoryLimit: c.MemoryLimit, diff --git a/internal/stage/model.go b/internal/stage/model.go index 62d1473..6b8b4c4 100644 --- a/internal/stage/model.go +++ b/internal/stage/model.go @@ -30,9 +30,11 @@ type CmdFile struct { // Cmd defines command and limits to start a program using in envexec type Cmd struct { - Args []string `json:"args"` - Env []string `json:"env,omitempty"` - Files []*CmdFile `json:"files,omitempty"` + Args []string `json:"args"` + Env []string `json:"env,omitempty"` + Stdin *CmdFile `json:"stdin,omitempty"` + Stdout *CmdFile `json:"stdout,omitempty"` + Stderr *CmdFile `json:"stderr,omitempty"` CPULimit uint64 `json:"cpuLimit"` RealCPULimit uint64 `json:"realCpuLimit"`