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

File read-able check should ignore file creation flags #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion memfs/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (f *file) ReadAt(b []byte, off int64) (int, error) {
return 0, os.ErrClosed
}

if !isReadAndWrite(f.flag) && !isReadOnly(f.flag) {
if isWriteOnly(f.flag) {
return 0, errors.New("read not supported")
}

Expand Down
6 changes: 6 additions & 0 deletions test/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ func (s *BasicSuite) TestOpenFile(c *C) {
c.Assert(f.Name(), Equals, "foo1")
s.testReadClose(c, f, "foo1overwritten")

// Read-only if it exists
f, err = s.FS.OpenFile("foo1", os.O_RDONLY|os.O_CREATE, defaultMode)
c.Assert(err, IsNil)
c.Assert(f.Name(), Equals, "foo1")
s.testReadClose(c, f, "foo1overwritten")

// Create when it does exist
f, err = s.FS.OpenFile("foo1", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, defaultMode)
c.Assert(err, IsNil)
Expand Down