set ModeDir on MkDir calls on MemMapFs

closes #118
This commit is contained in:
Martin Bertschler 2017-10-03 23:46:18 +02:00
parent 473997e418
commit 84cf6dc707
3 changed files with 13 additions and 25 deletions

View File

@ -141,7 +141,7 @@ func (m *MemMapFs) Mkdir(name string, perm os.FileMode) error {
m.registerWithParent(item) m.registerWithParent(item)
m.mu.Unlock() m.mu.Unlock()
m.Chmod(name, perm) m.Chmod(name, perm|os.ModeDir)
return nil return nil
} }
@ -151,9 +151,8 @@ func (m *MemMapFs) MkdirAll(path string, perm os.FileMode) error {
if err != nil { if err != nil {
if err.(*os.PathError).Err == ErrFileExists { if err.(*os.PathError).Err == ErrFileExists {
return nil return nil
} else {
return err
} }
return err
} }
return nil return nil
} }

View File

@ -110,6 +110,8 @@ func TestPermSet(t *testing.T) {
const dirPathAll = "/my/path/to/dir" const dirPathAll = "/my/path/to/dir"
const fileMode = os.FileMode(0765) const fileMode = os.FileMode(0765)
// directories will also have the directory bit set
const dirMode = fileMode | os.ModeDir
fs := NewMemMapFs() fs := NewMemMapFs()
@ -132,7 +134,7 @@ func TestPermSet(t *testing.T) {
} }
// Test Mkdir // Test Mkdir
err = fs.Mkdir(dirPath, fileMode) err = fs.Mkdir(dirPath, dirMode)
if err != nil { if err != nil {
t.Errorf("MkDir Create failed: %s", err) t.Errorf("MkDir Create failed: %s", err)
return return
@ -142,13 +144,14 @@ func TestPermSet(t *testing.T) {
t.Errorf("Stat failed: %s", err) t.Errorf("Stat failed: %s", err)
return return
} }
if s.Mode().String() != fileMode.String() { // sets File
t.Errorf("Permissions Incorrect: %s != %s", s.Mode().String(), fileMode.String()) if s.Mode().String() != dirMode.String() {
t.Errorf("Permissions Incorrect: %s != %s", s.Mode().String(), dirMode.String())
return return
} }
// Test MkdirAll // Test MkdirAll
err = fs.MkdirAll(dirPathAll, fileMode) err = fs.MkdirAll(dirPathAll, dirMode)
if err != nil { if err != nil {
t.Errorf("MkDir Create failed: %s", err) t.Errorf("MkDir Create failed: %s", err)
return return
@ -158,8 +161,8 @@ func TestPermSet(t *testing.T) {
t.Errorf("Stat failed: %s", err) t.Errorf("Stat failed: %s", err)
return return
} }
if s.Mode().String() != fileMode.String() { if s.Mode().String() != dirMode.String() {
t.Errorf("Permissions Incorrect: %s != %s", s.Mode().String(), fileMode.String()) t.Errorf("Permissions Incorrect: %s != %s", s.Mode().String(), dirMode.String())
return return
} }
} }
@ -402,7 +405,7 @@ func TestMemFsDirMode(t *testing.T) {
if !info.IsDir() { if !info.IsDir() {
t.Error("should be a directory") t.Error("should be a directory")
} }
if info.Mode()&os.ModeDir == 0 { if !info.Mode().IsDir() {
t.Error("FileMode is not directory") t.Error("FileMode is not directory")
} }
info, err = fs.Stat("/sub/testDir2") info, err = fs.Stat("/sub/testDir2")
@ -412,7 +415,7 @@ func TestMemFsDirMode(t *testing.T) {
if !info.IsDir() { if !info.IsDir() {
t.Error("should be a directory") t.Error("should be a directory")
} }
if info.Mode()&os.ModeDir == 0 { if !info.Mode().IsDir() {
t.Error("FileMode is not directory") t.Error("FileMode is not directory")
} }
} }

View File

@ -1,14 +0,0 @@
// Copyright © 2014 Steve Francia <spf@spf13.com>.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package afero