func (m *MemMapFs) getData() map[string]*mem.FileData { m.init.Do(func() { m.data = make(map[string]*mem.FileData) // Root should always exist, right? // TODO: what about windows? m.data[FilePathSeparator] = mem.CreateDir(FilePathSeparator) }) return m.data }
func (m *MemMapFs) lockfreeMkdir(name string, perm os.FileMode) error { name = normalizePath(name) x, ok := m.getData()[name] if ok { // Only return ErrFileExists if it's a file, not a directory. i := mem.FileInfo{x} if !i.IsDir() { return ErrFileExists } } else { item := mem.CreateDir(name) m.getData()[name] = item m.registerWithParent(item) } return nil }
func (m *MemMapFs) Mkdir(name string, perm os.FileMode) error { name = normalizePath(name) m.mu.RLock() _, ok := m.getData()[name] m.mu.RUnlock() if ok { return &os.PathError{"mkdir", name, ErrFileExists} } else { m.mu.Lock() item := mem.CreateDir(name) m.getData()[name] = item m.registerWithParent(item) m.mu.Unlock() } return nil }