MCPcopy
hub / github.com/httprunner/httprunner / locateFile

Function locateFile

hrp/plugin.go:124–154  ·  view source on GitHub ↗

locateFile searches destFile upward recursively until system root dir if not found, then searches in hrp executable dir

(startPath string, destFile string)

Source from the content-addressed store, hash-verified

122// locateFile searches destFile upward recursively until system root dir
123// if not found, then searches in hrp executable dir
124func locateFile(startPath string, destFile string) (pluginPath string, err error) {
125 stat, err := os.Stat(startPath)
126 if os.IsNotExist(err) {
127 return "", errors.Wrap(err, "start path not exists")
128 }
129
130 var startDir string
131 if stat.IsDir() {
132 startDir = startPath
133 } else {
134 startDir = filepath.Dir(startPath)
135 }
136 startDir, _ = filepath.Abs(startDir)
137
138 // convention over configuration
139 pluginPath = filepath.Join(startDir, destFile)
140 if _, err := os.Stat(pluginPath); err == nil {
141 return pluginPath, nil
142 }
143
144 // system root dir
145 parentDir, _ := filepath.Abs(filepath.Dir(startDir))
146 if parentDir == startDir {
147 if pluginPath, err = locateExecutable(destFile); err == nil {
148 return
149 }
150 return "", errors.New("searched to system root dir, plugin file not found")
151 }
152
153 return locateFile(parentDir, destFile)
154}
155
156// locateExecutable finds destFile in hrp executable dir
157func locateExecutable(destFile string) (string, error) {

Callers 3

TestLocateFileFunction · 0.85
locatePluginFunction · 0.85
GetProjectRootDirPathFunction · 0.85

Calls 3

locateExecutableFunction · 0.85
StatMethod · 0.65
IsDirMethod · 0.45

Tested by 1

TestLocateFileFunction · 0.68