mirror of https://github.com/spf13/afero.git
[MemMap] Fix a data race
Signed-off-by: Anton Tiurin <noxiouz@yandex.ru>
This commit is contained in:
parent
0efc34d380
commit
5849bf9936
12
memmap.go
12
memmap.go
|
@ -78,10 +78,11 @@ func (MemMapFs) Name() string { return "MemMapFS" }
|
||||||
|
|
||||||
func (m *MemMapFs) Create(name string) (File, error) {
|
func (m *MemMapFs) Create(name string) (File, error) {
|
||||||
m.lock()
|
m.lock()
|
||||||
m.getData()[name] = MemFileCreate(name)
|
file := MemFileCreate(name)
|
||||||
|
m.getData()[name] = file
|
||||||
m.unlock()
|
m.unlock()
|
||||||
m.registerDirs(m.getData()[name])
|
m.registerDirs(file)
|
||||||
return m.getData()[name], nil
|
return file, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MemMapFs) registerDirs(f File) {
|
func (m *MemMapFs) registerDirs(f File) {
|
||||||
|
@ -139,9 +140,10 @@ func (m *MemMapFs) Mkdir(name string, perm os.FileMode) error {
|
||||||
return ErrFileExists
|
return ErrFileExists
|
||||||
} else {
|
} else {
|
||||||
m.lock()
|
m.lock()
|
||||||
m.getData()[name] = &InMemoryFile{name: name, memDir: &MemDirMap{}, dir: true}
|
item := &InMemoryFile{name: name, memDir: &MemDirMap{}, dir: true}
|
||||||
|
m.getData()[name] = item
|
||||||
m.unlock()
|
m.unlock()
|
||||||
m.registerDirs(m.getData()[name])
|
m.registerDirs(item)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue