mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-04-03 07:18:49 +02:00
30 lines
626 B
Go
30 lines
626 B
Go
package path
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
func Path(root, path string) (string, error) {
|
|
if filepath.IsAbs(path) {
|
|
return "", fmt.Errorf("%s: app path is absolute", path)
|
|
}
|
|
appPath := filepath.Join(root, path)
|
|
if !strings.HasPrefix(appPath, filepath.Clean(root)) {
|
|
return "", fmt.Errorf("%s: app path outside root", path)
|
|
}
|
|
info, err := os.Stat(appPath)
|
|
if os.IsNotExist(err) {
|
|
return "", fmt.Errorf("%s: app path does not exist", path)
|
|
}
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if !info.IsDir() {
|
|
return "", fmt.Errorf("%s: app path is not a directory", path)
|
|
}
|
|
return appPath, nil
|
|
}
|