MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / getConfigSearchPaths

Function getConfigSearchPaths

app/cli/cmd/config.go:126–159  ·  view source on GitHub ↗

getConfigSearchPaths returns a slice of directory paths to search for the attestation configuration file. It starts from the current working directory and traverses up the directory tree up all the way to the root or until it finds a .git directory. The search paths are returned in order, with the c

()

Source from the content-addressed store, hash-verified

124// or until it finds a .git directory. The search paths are returned in order, with the current directory first.
125// Based out of golangci-lint traverse mechanism
126func getConfigSearchPaths() []string {
127 absPath, err := filepath.Abs(".")
128 if err != nil {
129 absPath = filepath.Clean(".")
130 }
131
132 var currentDir string
133 if isDir(absPath) {
134 currentDir = absPath
135 } else {
136 currentDir = filepath.Dir(absPath)
137 }
138
139 // find all dirs from it up to the root
140 searchPaths := []string{"./"}
141
142 for {
143 searchPaths = append(searchPaths, currentDir)
144
145 parent := filepath.Dir(currentDir)
146 if currentDir == parent || parent == "" {
147 break
148 }
149
150 // We also terminate if there is a .git directory
151 if _, err := os.Stat(filepath.Join(currentDir, ".git")); err == nil {
152 break
153 }
154
155 currentDir = parent
156 }
157
158 return searchPaths
159}
160
161func isDir(filename string) bool {
162 fi, err := os.Stat(filename)

Calls 1

isDirFunction · 0.85

Tested by

no test coverage detected