ReadProblemInfo 读取题目信息
(problemFile string, unpack, validate bool, workDir string)
| 156 | |
| 157 | // ReadProblemInfo 读取题目信息 |
| 158 | func ReadProblemInfo(problemFile string, unpack, validate bool, workDir string) (*commonStructs.JudgeConfiguration, string, error) { |
| 159 | pack, err := readProblemPackage(problemFile, unpack) |
| 160 | if err != nil { |
| 161 | return nil, "", err |
| 162 | } |
| 163 | config := commonStructs.JudgeConfiguration{} |
| 164 | utils.JSONBytesObject(pack.Configs, &config) |
| 165 | |
| 166 | err = doProblemPackageValidation(pack, validate) |
| 167 | if err != nil { |
| 168 | return nil, "", err |
| 169 | } |
| 170 | |
| 171 | if unpack { |
| 172 | zipReader, err := zip.OpenReader(pack.BodyPackageFile) |
| 173 | if err != nil { |
| 174 | return nil, "", errors.Errorf("open body file (%s) error: %s", problemFile, err.Error()) |
| 175 | } |
| 176 | defer zipReader.Close() |
| 177 | |
| 178 | err = UnZip(zipReader, workDir) |
| 179 | if err != nil { |
| 180 | return nil, "", err |
| 181 | } |
| 182 | configFile := path.Join(workDir, "problem.json") |
| 183 | fp, err := os.Create(configFile) |
| 184 | if err != nil { |
| 185 | return nil, "", err |
| 186 | } |
| 187 | defer fp.Close() |
| 188 | _, err = fp.Write(pack.Configs) |
| 189 | if err != nil { |
| 190 | return nil, "", err |
| 191 | } |
| 192 | return &config, configFile, nil |
| 193 | } |
| 194 | |
| 195 | return &config, "", nil |
| 196 | } |
| 197 | |
| 198 | // ReadProblemGPGInfo 读取题目携带的GPG信息 |
| 199 | func ReadProblemGPGInfo(problemFile string) (string, error) { |
no test coverage detected