From b048c8675d9136fc70e3d2ceade892533ab2e67d Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 5 Jun 2023 14:01:06 +0200 Subject: [PATCH] address comments --- cmd/fs/helpers.go | 14 ++++++++++++++ .../fs/helpers_test.go | 18 +++++++++--------- cmd/fs/ls.go | 4 ++-- libs/filer/dbfs_client.go | 10 ---------- 4 files changed, 25 insertions(+), 21 deletions(-) create mode 100644 cmd/fs/helpers.go rename libs/filer/dbfs_client_test.go => cmd/fs/helpers_test.go (65%) diff --git a/cmd/fs/helpers.go b/cmd/fs/helpers.go new file mode 100644 index 000000000..e456bff98 --- /dev/null +++ b/cmd/fs/helpers.go @@ -0,0 +1,14 @@ +package fs + +import ( + "fmt" + "strings" +) + +func resolveDbfsPath(path string) (string, error) { + if !strings.HasPrefix(path, "dbfs:/") { + return "", fmt.Errorf("expected dbfs path (with the dbfs:/ prefix): %s", path) + } + + return strings.TrimPrefix(path, "dbfs:"), nil +} diff --git a/libs/filer/dbfs_client_test.go b/cmd/fs/helpers_test.go similarity index 65% rename from libs/filer/dbfs_client_test.go rename to cmd/fs/helpers_test.go index e9d1f136b..1d174ef95 100644 --- a/libs/filer/dbfs_client_test.go +++ b/cmd/fs/helpers_test.go @@ -1,4 +1,4 @@ -package filer +package fs import ( "testing" @@ -7,32 +7,32 @@ import ( ) func TestResolveDbfsPath(t *testing.T) { - path, err := ResolveDbfsPath("dbfs:/") + path, err := resolveDbfsPath("dbfs:/") assert.NoError(t, err) assert.Equal(t, "/", path) - path, err = ResolveDbfsPath("dbfs:/abc") + path, err = resolveDbfsPath("dbfs:/abc") assert.NoError(t, err) assert.Equal(t, "/abc", path) - path, err = ResolveDbfsPath("dbfs:/a/b/c") + path, err = resolveDbfsPath("dbfs:/a/b/c") assert.NoError(t, err) assert.Equal(t, "/a/b/c", path) - path, err = ResolveDbfsPath("dbfs:/a/b/.") + path, err = resolveDbfsPath("dbfs:/a/b/.") assert.NoError(t, err) assert.Equal(t, "/a/b/.", path) - path, err = ResolveDbfsPath("dbfs:/a/../c") + path, err = resolveDbfsPath("dbfs:/a/../c") assert.NoError(t, err) assert.Equal(t, "/a/../c", path) - _, err = ResolveDbfsPath("dbf:/a/b/c") + _, err = resolveDbfsPath("dbf:/a/b/c") assert.ErrorContains(t, err, "expected dbfs path (with the dbfs:/ prefix): dbf:/a/b/c") - _, err = ResolveDbfsPath("/a/b/c") + _, 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") + _, err = resolveDbfsPath("dbfs:a/b/c") assert.ErrorContains(t, err, "expected dbfs path (with the dbfs:/ prefix): dbfs:a/b/c") } diff --git a/cmd/fs/ls.go b/cmd/fs/ls.go index c92393c08..7049db049 100644 --- a/cmd/fs/ls.go +++ b/cmd/fs/ls.go @@ -34,7 +34,7 @@ func toJsonDirEntry(f fs.DirEntry) (*jsonDirEntry, error) { // lsCmd represents the ls command var lsCmd = &cobra.Command{ - Use: "ls ", + Use: "ls DIR_PATH", Short: "Lists files", Long: `Lists files`, Args: cobra.ExactArgs(1), @@ -50,7 +50,7 @@ var lsCmd = &cobra.Command{ ctx := cmd.Context() w := root.WorkspaceClient(ctx) - path, err := filer.ResolveDbfsPath(args[0]) + path, err := resolveDbfsPath(args[0]) if err != nil { return err } diff --git a/libs/filer/dbfs_client.go b/libs/filer/dbfs_client.go index d1cf9270c..67878136b 100644 --- a/libs/filer/dbfs_client.go +++ b/libs/filer/dbfs_client.go @@ -3,13 +3,11 @@ package filer import ( "context" "errors" - "fmt" "io" "io/fs" "net/http" "path" "sort" - "strings" "time" "github.com/databricks/databricks-sdk-go" @@ -272,11 +270,3 @@ func (w *DbfsClient) Stat(ctx context.Context, name string) (fs.FileInfo, error) return dbfsFileInfo{*info}, nil } - -func ResolveDbfsPath(path string) (string, error) { - if !strings.HasPrefix(path, "dbfs:/") { - return "", fmt.Errorf("expected dbfs path (with the dbfs:/ prefix): %s", path) - } - - return strings.TrimPrefix(path, "dbfs:"), nil -}