vfs: make sure write only handles never truncate files they shouldn't

This commit is contained in:
Nick Craig-Wood 2017-11-20 18:01:42 +00:00
parent 76b151984c
commit 3fb4fe31d2
5 changed files with 94 additions and 20 deletions

View file

@ -111,7 +111,7 @@ func TestFileOpenWrite(t *testing.T) {
defer r.Finalise()
vfs, file, _ := fileCreate(t, r)
fd, err := file.OpenWrite()
fd, err := file.OpenWrite(os.O_WRONLY | os.O_TRUNC)
require.NoError(t, err)
newContents := []byte("this is some new contents")
@ -123,7 +123,7 @@ func TestFileOpenWrite(t *testing.T) {
assert.Equal(t, int64(25), file.Size())
vfs.Opt.ReadOnly = true
_, err = file.OpenWrite()
_, err = file.OpenWrite(os.O_WRONLY | os.O_TRUNC)
assert.Equal(t, EROFS, err)
}