package runner import ( "fmt" "git.0x7f.app/WOJ/woj-server/internal/e" "git.0x7f.app/WOJ/woj-server/pkg/file" "go.uber.org/zap" "os" "path" "path/filepath" ) var ( Prefix = "./resource/runner" ProblemDir = "./problem/" ScriptsDir = "./scripts/" UserDir = "./user/" TmpDir = "./tmp/" ) func init() { wd, err := os.Getwd() if err != nil { panic(err) } Prefix = path.Join(wd, Prefix) ProblemDir = path.Join(Prefix, ProblemDir) UserDir = path.Join(Prefix, UserDir) TmpDir = path.Join(Prefix, TmpDir) } func (s *service) ProblemExists(version uint) bool { problemPath := filepath.Join(ProblemDir, fmt.Sprintf("%d", version)) return file.Exist(problemPath) } func (s *service) check(version uint, user string, lang string) e.Status { if !s.ProblemExists(version) { s.log.Info("problem not exists", zap.Uint("version", version)) return e.RunnerProblemNotExist } userPath := filepath.Join(UserDir, user, fmt.Sprintf("%s.%s", user, lang)) if !file.Exist(userPath) { s.log.Info("user program not exists", zap.String("user", user), zap.String("lang", lang)) return e.RunnerUserNotExist } return e.Success } func (s *service) getLangInfo(config *Config, lang string) (configLanguage, bool) { for _, l := range config.Languages { if l.Lang == lang { return l, true } } return configLanguage{}, false } func (s *service) getLangScript(l *configLanguage, lang string) string { if l.Type == "default" { return "/woj/framework/template/default/" + lang + ".Makefile" } else { return "/woj/problem/judge/" + l.Script } }