mirror of https://github.com/spf13/afero.git
Treat existing files and directories differently in MemMapFS.
This commit is contained in:
parent
19b2cf0372
commit
3f6f746a75
18
memmap.go
18
memmap.go
|
@ -154,9 +154,16 @@ func (m *MemMapFs) registerWithParent(f File) {
|
|||
}
|
||||
|
||||
func (m *MemMapFs) lockfreeMkdir(name string, perm os.FileMode) error {
|
||||
_, ok := m.getData()[name]
|
||||
x, ok := m.getData()[name]
|
||||
if ok {
|
||||
// Only return ErrFileExists if it's a file, not a directory.
|
||||
i, err := x.Stat()
|
||||
if !i.IsDir() {
|
||||
return ErrFileExists
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
item := &InMemoryFile{name: name, memDir: &MemDirMap{}, dir: true}
|
||||
m.getData()[name] = item
|
||||
|
@ -167,10 +174,17 @@ func (m *MemMapFs) lockfreeMkdir(name string, perm os.FileMode) error {
|
|||
|
||||
func (m *MemMapFs) Mkdir(name string, perm os.FileMode) error {
|
||||
m.rlock()
|
||||
_, ok := m.getData()[name]
|
||||
x, ok := m.getData()[name]
|
||||
m.runlock()
|
||||
if ok {
|
||||
// Only return ErrFileExists if it's a file, not a directory.
|
||||
i, err := x.Stat()
|
||||
if !i.IsDir() {
|
||||
return ErrFileExists
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
m.lock()
|
||||
item := &InMemoryFile{name: name, memDir: &MemDirMap{}, dir: true}
|
||||
|
|
Loading…
Reference in New Issue