mirror of https://github.com/databricks/cli.git
manually check for dbfs prefix
This commit is contained in:
parent
492382caa1
commit
3dc47709d0
|
@ -7,9 +7,9 @@ import (
|
|||
"io"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/databricks/databricks-sdk-go"
|
||||
|
@ -18,8 +18,6 @@ import (
|
|||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
const DbfsScheme = "dbfs"
|
||||
|
||||
// Type that implements fs.DirEntry for DBFS.
|
||||
type dbfsDirEntry struct {
|
||||
dbfsFileInfo
|
||||
|
@ -276,15 +274,9 @@ func (w *DbfsClient) Stat(ctx context.Context, name string) (fs.FileInfo, error)
|
|||
}
|
||||
|
||||
func ResolveDbfsPath(path string) (string, error) {
|
||||
fileUri, err := url.Parse(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Only dbfs file scheme is supported
|
||||
if fileUri.Scheme != DbfsScheme {
|
||||
if !strings.HasPrefix(path, "dbfs:/") {
|
||||
return "", fmt.Errorf("expected dbfs path (with the dbfs:/ prefix): %s", path)
|
||||
}
|
||||
|
||||
return fileUri.Path, nil
|
||||
return strings.TrimPrefix(path, "dbfs:"), nil
|
||||
}
|
||||
|
|
|
@ -32,4 +32,7 @@ func TestResolveDbfsPath(t *testing.T) {
|
|||
|
||||
_, err = ResolveDbfsPath("/a/b/c")
|
||||
assert.ErrorContains(t, err, "expected dbfs path (with the dbfs:/ prefix): /a/b/c")
|
||||
|
||||
_, err = ResolveDbfsPath("dbfs:a/b/c")
|
||||
assert.ErrorContains(t, err, "expected dbfs path (with the dbfs:/ prefix): dbfs:a/b/c")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue