From aaac7f57a07e1ae5d3c66c63d91bb08fb7c6f91f Mon Sep 17 00:00:00 2001 From: Paul Pan Date: Sun, 28 Apr 2024 14:39:43 +0800 Subject: [PATCH] fix: problem config is not properly parsed --- internal/service/runner/problem_config.go | 36 +++++++++++++++++------ 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/internal/service/runner/problem_config.go b/internal/service/runner/problem_config.go index 87a7997..ff50016 100644 --- a/internal/service/runner/problem_config.go +++ b/internal/service/runner/problem_config.go @@ -54,6 +54,29 @@ var ( } ) +func (c *ConfigRuntime) InitWithDefault(fallback *ConfigRuntime) { + if c.Validate() != nil { + *c = *fallback + } else { + c.FillDefault() + } +} + +func (c *ConfigRuntime) FillDefault() { + if c.SoftMemoryLimit <= 0 { + // default to memory limit + c.SoftMemoryLimit = c.MemoryLimit + } + if c.NProcLimit <= 0 { + // default to not limited + c.NProcLimit = 0 + } + if c.WriteFileLimit <= 0 { + // default to 1mb + c.WriteFileLimit = 1 + } +} + func (c *ConfigRuntime) Validate() error { if c.TimeLimit <= 0 { return errors.New("time limit <= 0") @@ -222,16 +245,11 @@ func (s *service) ParseConfig(meta *JudgeMeta, skipCheck bool) (*Config, error) // fill default for idx := range config.Languages { - if config.Languages[idx].Runtime.Compile.Validate() != nil { - config.Languages[idx].Runtime.Compile = DefaultCompileRuntime - } - if config.Languages[idx].Runtime.Check.Validate() != nil { - config.Languages[idx].Runtime.Check = DefaultCheckRuntime - } - } - if config.Prebuild.Validate() != nil { - config.Prebuild = DefaultPrebuildRuntime + config.Languages[idx].Runtime.Compile.InitWithDefault(&DefaultCompileRuntime) + config.Languages[idx].Runtime.Check.InitWithDefault(&DefaultCheckRuntime) + config.Languages[idx].Runtime.Run.FillDefault() } + config.Prebuild.InitWithDefault(&DefaultPrebuildRuntime) if skipCheck { return config, nil