MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / CheckFileContainsStr

Method CheckFileContainsStr

cli/pkg/common/fs.go:176–202  ·  view source on GitHub ↗

检查指定文件中是否包含文本

(path, str string)

Source from the content-addressed store, hash-verified

174
175// 检查指定文件中是否包含文本
176func (fs *fileOperation) CheckFileContainsStr(path, str string) (bool, error) {
177 b := false
178 cmp := []byte(str)
179 f, err := os.Open(path)
180 if err != nil {
181 return false, err
182 }
183 defer f.Close()
184 input := bufio.NewScanner(f)
185
186 for input.Scan() {
187 info := input.Bytes()
188 if bytes.Contains(info, cmp) {
189 b = true
190 break
191 }
192
193 tokens := bytes.SplitN(input.Bytes(), []byte(" "), 10)
194 totalSize += float64(len(input.Bytes()))
195 if len(tokens) < 9 {
196 continue
197 }
198 strconv.ParseInt(string(tokens[8]), 10, 0)
199 }
200 totalSize = totalSize / (1 << 20)
201 return b, nil
202}

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected