From 84cf6dc70734caf7df4d35b2a9ae34fbcd2a2e6d Mon Sep 17 00:00:00 2001 From: Martin Bertschler Date: Tue, 3 Oct 2017 23:46:18 +0200 Subject: [PATCH] set ModeDir on MkDir calls on MemMapFs closes #118 --- memmap.go | 5 ++--- memmap_test.go | 19 +++++++++++-------- memradix.go | 14 -------------- 3 files changed, 13 insertions(+), 25 deletions(-) delete mode 100644 memradix.go diff --git a/memmap.go b/memmap.go index 14cd438..09498e7 100644 --- a/memmap.go +++ b/memmap.go @@ -141,7 +141,7 @@ func (m *MemMapFs) Mkdir(name string, perm os.FileMode) error { m.registerWithParent(item) m.mu.Unlock() - m.Chmod(name, perm) + m.Chmod(name, perm|os.ModeDir) return nil } @@ -151,9 +151,8 @@ func (m *MemMapFs) MkdirAll(path string, perm os.FileMode) error { if err != nil { if err.(*os.PathError).Err == ErrFileExists { return nil - } else { - return err } + return err } return nil } diff --git a/memmap_test.go b/memmap_test.go index 23a8881..09d8680 100644 --- a/memmap_test.go +++ b/memmap_test.go @@ -110,6 +110,8 @@ func TestPermSet(t *testing.T) { const dirPathAll = "/my/path/to/dir" const fileMode = os.FileMode(0765) + // directories will also have the directory bit set + const dirMode = fileMode | os.ModeDir fs := NewMemMapFs() @@ -132,7 +134,7 @@ func TestPermSet(t *testing.T) { } // Test Mkdir - err = fs.Mkdir(dirPath, fileMode) + err = fs.Mkdir(dirPath, dirMode) if err != nil { t.Errorf("MkDir Create failed: %s", err) return @@ -142,13 +144,14 @@ func TestPermSet(t *testing.T) { t.Errorf("Stat failed: %s", err) return } - if s.Mode().String() != fileMode.String() { - t.Errorf("Permissions Incorrect: %s != %s", s.Mode().String(), fileMode.String()) + // sets File + if s.Mode().String() != dirMode.String() { + t.Errorf("Permissions Incorrect: %s != %s", s.Mode().String(), dirMode.String()) return } // Test MkdirAll - err = fs.MkdirAll(dirPathAll, fileMode) + err = fs.MkdirAll(dirPathAll, dirMode) if err != nil { t.Errorf("MkDir Create failed: %s", err) return @@ -158,8 +161,8 @@ func TestPermSet(t *testing.T) { t.Errorf("Stat failed: %s", err) return } - if s.Mode().String() != fileMode.String() { - 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 } } @@ -402,7 +405,7 @@ func TestMemFsDirMode(t *testing.T) { if !info.IsDir() { t.Error("should be a directory") } - if info.Mode()&os.ModeDir == 0 { + if !info.Mode().IsDir() { t.Error("FileMode is not directory") } info, err = fs.Stat("/sub/testDir2") @@ -412,7 +415,7 @@ func TestMemFsDirMode(t *testing.T) { if !info.IsDir() { t.Error("should be a directory") } - if info.Mode()&os.ModeDir == 0 { + if !info.Mode().IsDir() { t.Error("FileMode is not directory") } } diff --git a/memradix.go b/memradix.go deleted file mode 100644 index 87527f3..0000000 --- a/memradix.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright © 2014 Steve Francia . -// -// 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