github.com/databricks/cli@v0.203.0/libs/filer/local_root_path.go (about) 1 package filer 2 3 import ( 4 "fmt" 5 "path/filepath" 6 "strings" 7 ) 8 9 type localRootPath struct { 10 rootPath string 11 } 12 13 func NewLocalRootPath(root string) localRootPath { 14 if root == "" { 15 return localRootPath{""} 16 } 17 return localRootPath{filepath.Clean(root)} 18 } 19 20 func (rp *localRootPath) Join(name string) (string, error) { 21 absPath := filepath.Join(rp.rootPath, name) 22 23 if !strings.HasPrefix(absPath, rp.rootPath) { 24 return "", fmt.Errorf("relative path escapes root: %s", name) 25 } 26 return absPath, nil 27 }