diff --git a/pkg/go-nfs/filesystem.go b/pkg/go-nfs/filesystem.go index 7aa66c6..2207173 100644 --- a/pkg/go-nfs/filesystem.go +++ b/pkg/go-nfs/filesystem.go @@ -26,10 +26,6 @@ type Filesystem interface { // it if it already exists. If successful, methods on the returned File can // be used for I/O; the associated file descriptor has mode O_RDWR. Create(ctx context.Context, filename string) (File, error) - // Open opens the named file for reading. If successful, methods on the - // returned file can be used for reading; the associated file descriptor has - // mode O_RDONLY. - Open(ctx context.Context, filename string) (File, error) // OpenFile is the generalized open call; most users will use Open or Create // instead. It opens the named file with specified flag (O_RDONLY etc.) and // perm, (0666 etc.) if applicable. If successful, methods on the returned diff --git a/pkg/go-nfs/nfs_onread.go b/pkg/go-nfs/nfs_onread.go index 107481a..6856ddc 100644 --- a/pkg/go-nfs/nfs_onread.go +++ b/pkg/go-nfs/nfs_onread.go @@ -42,7 +42,7 @@ func onRead(ctx context.Context, w *response, userHandle Handler) error { return &NFSStatusError{NFSStatusStale, err} } - fh, err := fs.Open(ctx, fs.Join(path...)) + fh, err := fs.OpenFile(ctx, fs.Join(path...), os.O_RDONLY, 0) if err != nil { if os.IsNotExist(err) { return &NFSStatusError{NFSStatusNoEnt, err} diff --git a/pkg/go-nfs/nfs_onwrite.go b/pkg/go-nfs/nfs_onwrite.go index 7fac090..536cc6c 100644 --- a/pkg/go-nfs/nfs_onwrite.go +++ b/pkg/go-nfs/nfs_onwrite.go @@ -72,6 +72,7 @@ func onWrite(ctx context.Context, w *response, userHandle Handler) error { if err != nil { return &NFSStatusError{NFSStatusAccess, err} } + defer file.Close(ctx) if req.Offset > 0 { if _, err := file.Seek(int64(req.Offset), io.SeekStart); err != nil { return &NFSStatusError{NFSStatusIO, err} diff --git a/pkg/go-nfs/nfs_test.go b/pkg/go-nfs/nfs_test.go index 8a79752..e0a9b36 100644 --- a/pkg/go-nfs/nfs_test.go +++ b/pkg/go-nfs/nfs_test.go @@ -5,6 +5,7 @@ import ( "context" "fmt" "net" + "os" "reflect" "sort" "testing" @@ -86,7 +87,7 @@ func TestNFS(t *testing.T) { if err != nil { t.Fatal(err) } - mf, _ := mem.Open(ctx, "/helloworld.txt") + mf, _ := mem.OpenFile(ctx, "/helloworld.txt", os.O_RDONLY, 0) buf := make([]byte, len(b)) if _, err = mf.Read(ctx, buf[:]); err != nil { t.Fatal(err)