manually check for dbfs prefix

This commit is contained in:
Shreyas Goenka 2023-06-05 02:13:28 +02:00
parent 492382caa1
commit 3dc47709d0
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
2 changed files with 6 additions and 11 deletions

View File

@ -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
}

View File

@ -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")
}