[MemMap] Fix a data race

Signed-off-by: Anton Tiurin <noxiouz@yandex.ru>
This commit is contained in:
Anton Tiurin 2015-06-11 21:49:27 +03:00 committed by spf13
parent 0efc34d380
commit 5849bf9936
1 changed files with 7 additions and 5 deletions

View File

@ -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
} }