mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
feat: add locateExecutable to finds plugin in hrp executable dir
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v4.3.6-beta
|
v4.3.6-2308191518
|
||||||
+25
-5
@@ -120,14 +120,15 @@ func locatePlugin(path string) (pluginPath string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", fmt.Errorf("plugin file not found")
|
return "", errors.New("plugin file not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
// locateFile searches destFile upward recursively until system root dir
|
// locateFile searches destFile upward recursively until system root dir
|
||||||
func locateFile(startPath string, destFile string) (string, error) {
|
// if not found, then searches in hrp executable dir
|
||||||
|
func locateFile(startPath string, destFile string) (pluginPath string, err error) {
|
||||||
stat, err := os.Stat(startPath)
|
stat, err := os.Stat(startPath)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return "", err
|
return "", errors.Wrap(err, "start path not exists")
|
||||||
}
|
}
|
||||||
|
|
||||||
var startDir string
|
var startDir string
|
||||||
@@ -139,7 +140,7 @@ func locateFile(startPath string, destFile string) (string, error) {
|
|||||||
startDir, _ = filepath.Abs(startDir)
|
startDir, _ = filepath.Abs(startDir)
|
||||||
|
|
||||||
// convention over configuration
|
// convention over configuration
|
||||||
pluginPath := filepath.Join(startDir, destFile)
|
pluginPath = filepath.Join(startDir, destFile)
|
||||||
if _, err := os.Stat(pluginPath); err == nil {
|
if _, err := os.Stat(pluginPath); err == nil {
|
||||||
return pluginPath, nil
|
return pluginPath, nil
|
||||||
}
|
}
|
||||||
@@ -147,12 +148,31 @@ func locateFile(startPath string, destFile string) (string, error) {
|
|||||||
// system root dir
|
// system root dir
|
||||||
parentDir, _ := filepath.Abs(filepath.Dir(startDir))
|
parentDir, _ := filepath.Abs(filepath.Dir(startDir))
|
||||||
if parentDir == startDir {
|
if parentDir == startDir {
|
||||||
return "", fmt.Errorf("searched to system root dir, plugin file not found")
|
if pluginPath, err = locateExecutable(destFile); err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return "", errors.New("searched to system root dir, plugin file not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
return locateFile(parentDir, destFile)
|
return locateFile(parentDir, destFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// locateExecutable finds destFile in hrp executable dir
|
||||||
|
func locateExecutable(destFile string) (string, error) {
|
||||||
|
exePath, err := os.Executable()
|
||||||
|
if err != nil {
|
||||||
|
return "", errors.Wrap(err, "get hrp executable failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
exeDir := filepath.Dir(exePath)
|
||||||
|
pluginPath := filepath.Join(exeDir, destFile)
|
||||||
|
if _, err := os.Stat(pluginPath); err == nil {
|
||||||
|
return pluginPath, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", errors.New("plugin file not found in hrp executable dir")
|
||||||
|
}
|
||||||
|
|
||||||
func GetProjectRootDirPath(path string) (rootDir string, err error) {
|
func GetProjectRootDirPath(path string) (rootDir string, err error) {
|
||||||
pluginPath, err := locatePlugin(path)
|
pluginPath, err := locatePlugin(path)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user