MCPcopy Create free account
hub / github.com/LanceLRQ/deer-executor / ReadProblemInfoZip

Function ReadProblemInfoZip

common/persistence/problems/reader_zip.go:94–129  ·  view source on GitHub ↗

ReadProblemInfoZip 读取题目信息(ZIP) workDir只在需要解压的时候才会用到

(problemFile string, unpack, validate bool, workDir string)

Source from the content-addressed store, hash-verified

92// ReadProblemInfoZip 读取题目信息(ZIP)
93// workDir只在需要解压的时候才会用到
94func 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)
132func ReadProblemGPGInfoZip(problemFile string) (string, error) {

Callers 3

UnpackProblemPackageFunction · 0.92
ReadProblemInfoFunction · 0.92
loadProblemConfigurationFunction · 0.92

Calls 6

JSONBytesObjectFunction · 0.92
FindInZipFunction · 0.85
UnZipFunction · 0.85
ErrorfMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected