ReadProblemInfoZip 读取题目信息(ZIP) workDir只在需要解压的时候才会用到
(problemFile string, unpack, validate bool, workDir string)
| 92 | // ReadProblemInfoZip 读取题目信息(ZIP) |
| 93 | // workDir只在需要解压的时候才会用到 |
| 94 | func ReadProblemInfoZip(problemFile string, unpack, validate bool, workDir string) (*commonStructs.JudgeConfiguration, string, error) { |
| 95 | // 打开文件 |
| 96 | zipReader, err := zip.OpenReader(problemFile) |
| 97 | if err != nil { |
| 98 | return nil, "", errors.Errorf("open file (%s) error: %s", problemFile, err.Error()) |
| 99 | } |
| 100 | defer zipReader.Close() |
| 101 | |
| 102 | config := commonStructs.JudgeConfiguration{} |
| 103 | // 搜索config文件 |
| 104 | configFile, _, err := FindInZip(zipReader, "problem.json") |
| 105 | if err != nil { |
| 106 | return nil, "", err |
| 107 | } |
| 108 | // 读取Config信息 |
| 109 | configByte, err := ioutil.ReadAll(*configFile) |
| 110 | if err != nil { |
| 111 | return nil, "", err |
| 112 | } |
| 113 | utils.JSONBytesObject(configByte, &config) |
| 114 | // 校验签名 |
| 115 | err = doProblemPackageValidationZip(zipReader, validate) |
| 116 | if err != nil { |
| 117 | return nil, "", err |
| 118 | } |
| 119 | |
| 120 | if unpack { |
| 121 | // 解压 |
| 122 | err = UnZip(zipReader, workDir) |
| 123 | if err != nil { |
| 124 | return nil, "", err |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | return &config, path.Join(workDir, "problem.json"), nil |
| 129 | } |
| 130 | |
| 131 | // ReadProblemGPGInfoZip 读取题目携带的GPG信息(ZIP) |
| 132 | func ReadProblemGPGInfoZip(problemFile string) (string, error) { |
no test coverage detected