MCPcopy Create free account
hub / github.com/archlinux-de/pkgstats-cli / readConfigFile

Method readConfigFile

internal/pacman/parser.go:68–99  ·  view source on GitHub ↗
(fileName string, depth int)

Source from the content-addressed store, hash-verified

66}
67
68func (parser *parser) readConfigFile(fileName string, depth int) ([]string, error) {
69 if depth >= configMaxRecursion {
70 return nil, fmt.Errorf("reached maximum Include depth of %d", depth)
71 }
72 readFile, err := os.Open(fileName)
73 if err != nil {
74 return nil, err
75 }
76 defer readFile.Close()
77
78 fileScanner := bufio.NewScanner(readFile)
79 var fileLines []string
80 for fileScanner.Scan() {
81 line := strings.TrimSpace(fileScanner.Text())
82 if isCommentOrEmpty(line) {
83 continue
84 }
85 if isIncludeLine(line) {
86 includeLines, err := parser.processIncludeLine(line, depth+1)
87 if err != nil {
88 return nil, err
89 }
90 fileLines = append(fileLines, includeLines...)
91 } else {
92 fileLines = append(fileLines, line)
93 }
94 }
95 if err := fileScanner.Err(); err != nil {
96 return nil, err
97 }
98 return fileLines, nil
99}
100
101func (parser *parser) processIncludeLine(line string, depth int) ([]string, error) {
102 const expectedParts = 2

Callers 2

parseConfigFileMethod · 0.95
processIncludeLineMethod · 0.95

Calls 3

processIncludeLineMethod · 0.95
isCommentOrEmptyFunction · 0.85
isIncludeLineFunction · 0.85

Tested by

no test coverage detected