Skip to content

Commit

Permalink
Fix spf13#415
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Schmidt committed Feb 7, 2024
1 parent 5c4385a commit cf893f2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion memmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (m *MemMapFs) OpenFile(name string, flag int, perm os.FileMode) (File, erro
perm &= chmodBits
chmod := false
file, err := m.openWrite(name)
if err == nil && (flag&os.O_EXCL > 0) {
if err == nil && (flag&(os.O_CREATE|os.O_EXCL)) == (os.O_CREATE|os.O_EXCL) {
return nil, &os.PathError{Op: "open", Path: name, Err: ErrFileExists}
}
if os.IsNotExist(err) && (flag&os.O_CREATE > 0) {
Expand Down
22 changes: 22 additions & 0 deletions memmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,3 +918,25 @@ func TestMemMapFsRename(t *testing.T) {
}
}
}

func TestMemMapCreateThenOpen(t *testing.T) {
fs := NewMemMapFs()
filePath := "/test/data.txt"
err := fs.MkdirAll("/test", 0744)
if err != nil {
t.Fatal(err)
}
f1, err := fs.OpenFile(filePath, os.O_CREATE|os.O_RDWR|os.O_EXCL, 0644)
if err != nil {
t.Fatal(err)
}
err = f1.Close()
if err != nil {
t.Fatal(err)
}
f2, err := fs.OpenFile(filePath, os.O_RDWR|os.O_EXCL, 0644)
if err != nil {
t.Fatal(err)
}
f2.Close()
}

0 comments on commit cf893f2

Please sign in to comment.