aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/spf13/afero/memmap.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/spf13/afero/memmap.go')
-rw-r--r--vendor/github.com/spf13/afero/memmap.go38
1 files changed, 25 insertions, 13 deletions
diff --git a/vendor/github.com/spf13/afero/memmap.go b/vendor/github.com/spf13/afero/memmap.go
index 2e259b8..494ba54 100644
--- a/vendor/github.com/spf13/afero/memmap.go
+++ b/vendor/github.com/spf13/afero/memmap.go
@@ -35,8 +35,6 @@ func NewMemMapFs() Fs {
return &MemMapFs{}
}
-var memfsInit sync.Once
-
func (m *MemMapFs) getData() map[string]*mem.FileData {
m.init.Do(func() {
m.data = make(map[string]*mem.FileData)
@@ -130,13 +128,16 @@ func (m *MemMapFs) Mkdir(name string, perm os.FileMode) error {
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()
}
+
+ m.mu.Lock()
+ item := mem.CreateDir(name)
+ m.getData()[name] = item
+ m.registerWithParent(item)
+ m.mu.Unlock()
+
+ m.Chmod(name, perm)
+
return nil
}
@@ -205,9 +206,11 @@ func (m *MemMapFs) lockfreeOpen(name string) (*mem.FileData, error) {
}
func (m *MemMapFs) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
+ chmod := false
file, err := m.openWrite(name)
if os.IsNotExist(err) && (flag&os.O_CREATE > 0) {
file, err = m.Create(name)
+ chmod = true
}
if err != nil {
return nil, err
@@ -229,6 +232,9 @@ func (m *MemMapFs) OpenFile(name string, flag int, perm os.FileMode) (File, erro
return nil, err
}
}
+ if chmod {
+ m.Chmod(name, perm)
+ }
return file, nil
}
@@ -309,7 +315,10 @@ func (m *MemMapFs) Stat(name string) (os.FileInfo, error) {
func (m *MemMapFs) Chmod(name string, mode os.FileMode) error {
name = normalizePath(name)
+
+ m.mu.RLock()
f, ok := m.getData()[name]
+ m.mu.RUnlock()
if !ok {
return &os.PathError{"chmod", name, ErrFileNotFound}
}
@@ -323,7 +332,10 @@ func (m *MemMapFs) Chmod(name string, mode os.FileMode) error {
func (m *MemMapFs) Chtimes(name string, atime time.Time, mtime time.Time) error {
name = normalizePath(name)
+
+ m.mu.RLock()
f, ok := m.getData()[name]
+ m.mu.RUnlock()
if !ok {
return &os.PathError{"chtimes", name, ErrFileNotFound}
}
@@ -342,8 +354,8 @@ func (m *MemMapFs) List() {
}
}
-func debugMemMapList(fs Fs) {
- if x, ok := fs.(*MemMapFs); ok {
- x.List()
- }
-}
+// func debugMemMapList(fs Fs) {
+// if x, ok := fs.(*MemMapFs); ok {
+// x.List()
+// }
+// }