Fix MemMapFs.Remove() to really delete the file. It was attempting to delete a file with a hardcoded path of "name" as opposed to the path in the `name` variable. Fixing this exposed a deadlock because the function was attempting to acquire an exclusive lock when it already had a read lock.
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 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) 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 }