Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when opening a DBFS directory for reading #415

Merged
merged 2 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions internal/dbfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,35 @@ func TestAccDbfsOpen(t *testing.T) {
}
}

func TestAccDbfsOpenDirectory(t *testing.T) {
ctx, w := workspaceTest(t)
if w.Config.IsGcp() {
t.Skip("dbfs not available on gcp")
}

path := RandomName("/tmp/.sdk/fake")

defer w.Dbfs.Delete(ctx, files.Delete{
Path: path,
})

// Create directory.
err := w.Dbfs.MkdirsByPath(ctx, path)
require.NoError(t, err)

// Try to open the directory for reading.
_, err = w.Dbfs.Open(ctx, path, files.FileModeRead)
assert.ErrorContains(t, err, "dbfs open: cannot open directory for reading")

// Try to open the directory for writing.
_, err = w.Dbfs.Open(ctx, path, files.FileModeWrite)
assert.ErrorContains(t, err, "dbfs open: A file or directory already exists")

// Try to open the directory for writing with overwrite flag set.
_, err = w.Dbfs.Open(ctx, path, files.FileModeWrite|files.FileModeOverwrite)
assert.ErrorContains(t, err, "dbfs open: A file or directory already exists")
}

func TestAccDbfsReadFileWriteFile(t *testing.T) {
ctx, w := workspaceTest(t)
if w.Config.IsGcp() {
Expand Down
3 changes: 3 additions & 0 deletions service/files/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ func (h *fileHandle) openForRead(mode FileMode) error {
if err != nil {
return err
}
if res.IsDir {
return fmt.Errorf("cannot open directory for reading")
}
h.reader = &fileHandleReader{
size: res.FileSize,
}
Expand Down