diff --git a/fs_test.go b/fs_test.go index 225100e..36925e6 100644 --- a/fs_test.go +++ b/fs_test.go @@ -114,6 +114,24 @@ func TestRename(t *testing.T) { } } +func TestRemove(t *testing.T) { + for _, fs := range Fss { + path := testDir + "/" + testName + fs.MkdirAll(testDir, 0777) // Just in case. + fs.Create(path) + + err := fs.Remove(path) + if err != nil { + t.Fatalf("%v: Remove() failed: %v", fs.Name(), err) + } + + _, err = fs.Stat(path) + if !os.IsNotExist(err) { + t.Errorf("%v: Remove() didn't remove file", fs.Name()) + } + } +} + func TestTruncate(t *testing.T) { for _, fs := range Fss { f := newFile("TestTruncate", fs, t) diff --git a/memmap.go b/memmap.go index 134c67f..b12969c 100644 --- a/memmap.go +++ b/memmap.go @@ -173,13 +173,11 @@ func (m *MemMapFs) OpenFile(name string, flag int, perm os.FileMode) (File, erro } func (m *MemMapFs) Remove(name string) error { - m.rlock() - defer m.runlock() + m.lock() + defer m.unlock() - if _, ok := m.getData()["name"]; ok { - m.lock() + if _, ok := m.getData()[name]; ok { delete(m.getData(), name) - m.unlock() } return nil }