mirror of https://github.com/databricks/cli.git
add check for isdir in readdir
This commit is contained in:
parent
fb5ea166ca
commit
931fae1fd4
|
@ -222,6 +222,10 @@ func (w *DbfsClient) ReadDir(ctx context.Context, name string) ([]fs.DirEntry, e
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if len(res.Files) == 1 && !res.Files[0].IsDir && res.Files[0].Path == absPath {
|
||||
return nil, NotADirectory{absPath}
|
||||
}
|
||||
|
||||
info := make([]fs.DirEntry, len(res.Files))
|
||||
for i, v := range res.Files {
|
||||
info[i] = dbfsDirEntry{dbfsFileInfo: dbfsFileInfo{fi: v}}
|
||||
|
|
|
@ -2,6 +2,7 @@ package filer
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
|
@ -50,6 +51,20 @@ func (err NoSuchDirectoryError) Is(other error) bool {
|
|||
return other == fs.ErrNotExist
|
||||
}
|
||||
|
||||
var ErrNotADirectory = errors.New("not a directory")
|
||||
|
||||
type NotADirectory struct {
|
||||
path string
|
||||
}
|
||||
|
||||
func (err NotADirectory) Error() string {
|
||||
return fmt.Sprintf("%s is not a directory", err.path)
|
||||
}
|
||||
|
||||
func (err NotADirectory) Is(other error) bool {
|
||||
return other == ErrNotADirectory
|
||||
}
|
||||
|
||||
// Filer is used to access files in a workspace.
|
||||
// It has implementations for accessing files in WSFS and in DBFS.
|
||||
type Filer interface {
|
||||
|
|
|
@ -222,6 +222,12 @@ func (w *WorkspaceFilesClient) ReadDir(ctx context.Context, name string) ([]fs.D
|
|||
objects, err := w.workspaceClient.Workspace.ListAll(ctx, workspace.ListWorkspaceRequest{
|
||||
Path: absPath,
|
||||
})
|
||||
|
||||
// TODO: add integration test for this
|
||||
if len(objects) == 1 && objects[0].Path == absPath {
|
||||
return nil, NotADirectory{absPath}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
// If we got an API error we deal with it below.
|
||||
var aerr *apierr.APIError
|
||||
|
|
Loading…
Reference in New Issue