mirror of https://github.com/databricks/cli.git
This commit is contained in:
parent
eb4710f3a9
commit
32786e009a
|
@ -11,19 +11,17 @@ type WindowsRootPath struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWindowsRootPath(name string) WindowsRootPath {
|
func NewWindowsRootPath(name string) WindowsRootPath {
|
||||||
// Windows file systems do not have a "root" directory. Instead paths require
|
|
||||||
// a Volume/Drive letter specified. If a user of this struct specifies "/" then
|
|
||||||
// we treat it as the "root" and skip any validation
|
|
||||||
if name == "/" {
|
|
||||||
return WindowsRootPath{""}
|
|
||||||
}
|
|
||||||
|
|
||||||
return WindowsRootPath{filepath.Clean(name)}
|
return WindowsRootPath{filepath.Clean(name)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join returns the specified path name joined to the root.
|
|
||||||
// It returns an error if the resulting path is not a strict child of the root path.
|
|
||||||
func (p WindowsRootPath) Join(name string) (string, error) {
|
func (p WindowsRootPath) Join(name string) (string, error) {
|
||||||
|
// Windows file systems do not have a "root" directory. Instead paths require
|
||||||
|
// a Volume/Drive letter specified. If a user of this struct specifies "/" then
|
||||||
|
// we treat it as the "root" and skip any validation
|
||||||
|
if p.rootPath == "/" {
|
||||||
|
return name, nil
|
||||||
|
}
|
||||||
|
|
||||||
absPath := filepath.Join(p.rootPath, name)
|
absPath := filepath.Join(p.rootPath, name)
|
||||||
|
|
||||||
// Don't allow escaping the specified root using relative paths.
|
// Don't allow escaping the specified root using relative paths.
|
||||||
|
|
|
@ -15,7 +15,7 @@ func TestWindowsRootPathForRoot(t *testing.T) {
|
||||||
rp := NewWindowsRootPath("/")
|
rp := NewWindowsRootPath("/")
|
||||||
|
|
||||||
// Assert root value returned
|
// Assert root value returned
|
||||||
assert.Equal(t, "", rp.Root())
|
assert.Equal(t, "/", rp.Root())
|
||||||
|
|
||||||
// case: absolute windows path
|
// case: absolute windows path
|
||||||
path, err := rp.Join(`c:\a\b`)
|
path, err := rp.Join(`c:\a\b`)
|
||||||
|
|
Loading…
Reference in New Issue