forked from mirror/afero
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.
This commit is contained in:
parent
5849bf9936
commit
a269144fd6
18
fs_test.go
18
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) {
|
func TestTruncate(t *testing.T) {
|
||||||
for _, fs := range Fss {
|
for _, fs := range Fss {
|
||||||
f := newFile("TestTruncate", fs, t)
|
f := newFile("TestTruncate", fs, t)
|
||||||
|
|
|
@ -173,13 +173,11 @@ func (m *MemMapFs) OpenFile(name string, flag int, perm os.FileMode) (File, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MemMapFs) Remove(name string) error {
|
func (m *MemMapFs) Remove(name string) error {
|
||||||
m.rlock()
|
|
||||||
defer m.runlock()
|
|
||||||
|
|
||||||
if _, ok := m.getData()["name"]; ok {
|
|
||||||
m.lock()
|
m.lock()
|
||||||
|
defer m.unlock()
|
||||||
|
|
||||||
|
if _, ok := m.getData()[name]; ok {
|
||||||
delete(m.getData(), name)
|
delete(m.getData(), name)
|
||||||
m.unlock()
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue