Skip to content

Commit

Permalink
Error when opening a DBFS directory for reading (#415)
Browse files Browse the repository at this point in the history
## Changes

Fixes #414.

## Tests

- [x] `make test` passing
- [x] `make fmt` applied
- [x] relevant integration tests applied
  • Loading branch information
pietern authored Jun 7, 2023
1 parent 2da40a7 commit 8a0ee71
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
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

0 comments on commit 8a0ee71

Please sign in to comment.