github.com/argoproj/argo-cd@v1.8.7/util/app/path/path.go (about) 1 package path 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 "strings" 8 ) 9 10 func Path(root, path string) (string, error) { 11 if filepath.IsAbs(path) { 12 return "", fmt.Errorf("%s: app path is absolute", path) 13 } 14 appPath := filepath.Join(root, path) 15 if !strings.HasPrefix(appPath, filepath.Clean(root)) { 16 return "", fmt.Errorf("%s: app path outside root", path) 17 } 18 info, err := os.Stat(appPath) 19 if os.IsNotExist(err) { 20 return "", fmt.Errorf("%s: app path does not exist", path) 21 } 22 if err != nil { 23 return "", err 24 } 25 if !info.IsDir() { 26 return "", fmt.Errorf("%s: app path is not a directory", path) 27 } 28 return appPath, nil 29 }