diff --git a/hrp/internal/version/VERSION b/hrp/internal/version/VERSION index 7476a89a..16c8c5ae 100644 --- a/hrp/internal/version/VERSION +++ b/hrp/internal/version/VERSION @@ -1 +1 @@ -v4.3.6-beta \ No newline at end of file +v4.3.6-2308191518 \ No newline at end of file diff --git a/hrp/plugin.go b/hrp/plugin.go index 839d2d9f..be494fed 100644 --- a/hrp/plugin.go +++ b/hrp/plugin.go @@ -120,14 +120,15 @@ func locatePlugin(path string) (pluginPath string, err error) { return } - return "", fmt.Errorf("plugin file not found") + return "", errors.New("plugin file not found") } // 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) if os.IsNotExist(err) { - return "", err + return "", errors.Wrap(err, "start path not exists") } var startDir string @@ -139,7 +140,7 @@ func locateFile(startPath string, destFile string) (string, error) { startDir, _ = filepath.Abs(startDir) // convention over configuration - pluginPath := filepath.Join(startDir, destFile) + pluginPath = filepath.Join(startDir, destFile) if _, err := os.Stat(pluginPath); err == nil { return pluginPath, nil } @@ -147,12 +148,31 @@ func locateFile(startPath string, destFile string) (string, error) { // system root dir parentDir, _ := filepath.Abs(filepath.Dir(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) } +// 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) { pluginPath, err := locatePlugin(path) if err == nil {