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

Function readFileWithTry

executor/utils.go:31–52  ·  view source on GitHub ↗

文件读写(有重试次数,checker专用)

(filePath string, name string, tryOnFailed int)

Source from the content-addressed store, hash-verified

29
30// 文件读写(有重试次数,checker专用)
31func readFileWithTry(filePath string, name string, tryOnFailed int) ([]byte, string, error) {
32 errCnt, errText := 0, ""
33 var err error
34 for errCnt < tryOnFailed {
35 fp, err := os.OpenFile(filePath, os.O_RDONLY|syscall.O_NONBLOCK, 0)
36 if err != nil {
37 errText = err.Error()
38 errCnt++
39 continue
40 }
41 data, err := ioutil.ReadAll(fp)
42 if err != nil {
43 _ = fp.Close()
44 errText = fmt.Sprintf("Read file(%s) i/o error: %s", name, err.Error())
45 errCnt++
46 continue
47 }
48 _ = fp.Close()
49 return data, errText, nil
50 }
51 return nil, errText, err
52}
53
54// CheckRequireFilesExists 检查配置文件里的所有文件是否存在
55func CheckRequireFilesExists(config *commonStructs.JudgeConfiguration, configDir string) error {

Callers 1

DiffTextMethod · 0.85

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected