databricks-cli/libs/filer/local_root_path.go

27 lines
498 B
Go
Raw Normal View History

package filer
import (
"fmt"
"path/filepath"
"strings"
)
type localRootPath struct {
rootPath string
}
func NewLocalRootPath(root string) localRootPath {
if root == "" {
return localRootPath{""}
}
return localRootPath{filepath.Clean(root)}
}
func (rp *localRootPath) Join(name string) (string, error) {
absPath := filepath.Join(rp.rootPath, name)
if !strings.HasPrefix(absPath, rp.rootPath) {
return "", fmt.Errorf("relative path escapes root: %s", name)
}
return absPath, nil
}