forked from mirror/afero
Handle O_CREATE flag to *MemMapFs.OpenFile.
To allow MemMapFs to be used in place of OsFs in tests where this flag is used to create the file if it doesn't already exist..
This commit is contained in:
parent
42d35dace7
commit
47e9336de6
15
fs_test.go
15
fs_test.go
|
@ -70,6 +70,21 @@ func TestRead0(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestOpenFile(t *testing.T) {
|
||||
for _, fs := range Fss {
|
||||
path := testDir + "/" + testName
|
||||
fs.MkdirAll(testDir, 0777) // Just in case.
|
||||
fs.Remove(path) // Just in case.
|
||||
|
||||
f, err := fs.OpenFile(path, os.O_CREATE, 0600)
|
||||
if err != nil {
|
||||
t.Error(fs.Name(), "OpenFile (O_CREATE) failed:", err)
|
||||
continue
|
||||
}
|
||||
f.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func TestMemFileRead(t *testing.T) {
|
||||
f := MemFileCreate("testfile")
|
||||
f.WriteString("abcd")
|
||||
|
|
|
@ -205,7 +205,11 @@ func (m *MemMapFs) lockfreeOpen(name string) (File, error) {
|
|||
}
|
||||
|
||||
func (m *MemMapFs) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
|
||||
return m.Open(name)
|
||||
file, err := m.Open(name)
|
||||
if os.IsNotExist(err) && (flag&os.O_CREATE > 0) {
|
||||
file, err = m.Create(name)
|
||||
}
|
||||
return file, err
|
||||
}
|
||||
|
||||
func (m *MemMapFs) Remove(name string) error {
|
||||
|
|
Loading…
Reference in New Issue