2023-06-05 15:41:30 +00:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
2023-06-16 15:09:08 +00:00
|
|
|
"context"
|
2023-06-05 15:41:30 +00:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
2023-06-16 15:09:08 +00:00
|
|
|
|
|
|
|
"github.com/databricks/cli/cmd/root"
|
|
|
|
"github.com/databricks/cli/libs/filer"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Scheme string
|
|
|
|
|
|
|
|
const (
|
|
|
|
DbfsScheme = Scheme("dbfs")
|
|
|
|
LocalScheme = Scheme("file")
|
|
|
|
NoScheme = Scheme("")
|
2023-06-05 15:41:30 +00:00
|
|
|
)
|
|
|
|
|
2023-06-16 15:09:08 +00:00
|
|
|
func filerForPath(ctx context.Context, fullPath string) (filer.Filer, string, error) {
|
|
|
|
parts := strings.SplitN(fullPath, ":/", 2)
|
|
|
|
if len(parts) < 2 {
|
|
|
|
return nil, "", fmt.Errorf(`no scheme specified for path %s. Please specify scheme "dbfs" or "file". Example: file:/foo/bar or file:/c:/foo/bar`, fullPath)
|
2023-06-05 15:41:30 +00:00
|
|
|
}
|
2023-06-16 15:09:08 +00:00
|
|
|
scheme := Scheme(parts[0])
|
|
|
|
path := parts[1]
|
|
|
|
switch scheme {
|
|
|
|
case DbfsScheme:
|
|
|
|
w := root.WorkspaceClient(ctx)
|
|
|
|
f, err := filer.NewDbfsClient(w, "/")
|
|
|
|
return f, path, err
|
|
|
|
|
|
|
|
case LocalScheme:
|
|
|
|
f, err := filer.NewLocalClient("/")
|
|
|
|
return f, path, err
|
2023-06-05 15:41:30 +00:00
|
|
|
|
2023-06-16 15:09:08 +00:00
|
|
|
default:
|
|
|
|
return nil, "", fmt.Errorf(`unsupported scheme %s specified for path %s. Please specify scheme "dbfs" or "file". Example: file:/foo/bar or file:/c:/foo/bar`, scheme, fullPath)
|
|
|
|
}
|
2023-06-05 15:41:30 +00:00
|
|
|
}
|