From 3fc0d6fb2bd7d3a9d6f3c0577502e9a6df666da9 Mon Sep 17 00:00:00 2001 From: Martin Bertschler Date: Sun, 22 Nov 2015 14:26:00 +0100 Subject: [PATCH 1/2] make TestRename fail, make tests less verbose when they don't fail TestRename fails now because MemMapFs.Rename does not change the filename in the parent's memDir --- fs_test.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/fs_test.go b/fs_test.go index 0097335..79cda90 100644 --- a/fs_test.go +++ b/fs_test.go @@ -143,6 +143,22 @@ func TestRename(t *testing.T) { if err != nil { t.Fatalf("rename %q, %q failed: %v", to, from, err) } + names, err := readDirNames(testDir, fs) + if err != nil { + t.Fatalf("readDirNames error: %v", err) + } + found := false + for _, e := range names { + if e == "renamefrom" { + t.Error("File is still called renamefrom") + } + if e == "renameto" { + found = true + } + } + if !found { + t.Error("File was not renamed to renameto") + } defer fs.Remove(to) _, err = fs.Stat(to) if err != nil { @@ -512,9 +528,6 @@ func TestReaddirAll(t *testing.T) { } func findNames(t *testing.T, root, sub []string, fs Fs) { - t.Logf("Names root: %v", root) - t.Logf("Names sub: %v", sub) - var foundRoot bool for _, e := range root { _, err := fs.Open(path.Join(testDir, e)) @@ -526,6 +539,8 @@ func findNames(t *testing.T, root, sub []string, fs Fs) { } } if !foundRoot { + t.Logf("Names root: %v", root) + t.Logf("Names sub: %v", sub) t.Error("Didn't find subdirectory we") } @@ -544,9 +559,13 @@ func findNames(t *testing.T, root, sub []string, fs Fs) { } if !found1 { + t.Logf("Names root: %v", root) + t.Logf("Names sub: %v", sub) t.Error("Didn't find testfile1") } if !found2 { + t.Logf("Names root: %v", root) + t.Logf("Names sub: %v", sub) t.Error("Didn't find testfile2") } } From 5a59c3f940aafbdc494834f1ce72b6cc59e6bc20 Mon Sep 17 00:00:00 2001 From: Martin Bertschler Date: Sun, 22 Nov 2015 14:34:57 +0100 Subject: [PATCH 2/2] properly rename files by changing file.name and newly registering with parent --- memmap.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/memmap.go b/memmap.go index 8a0e3be..3bf85f7 100644 --- a/memmap.go +++ b/memmap.go @@ -293,8 +293,12 @@ func (m *MemMapFs) Rename(oldname, newname string) error { if _, ok := m.getData()[newname]; !ok { m.runlock() m.lock() - m.getData()[newname] = m.getData()[oldname] + m.unRegisterWithParent(oldname) + file := m.getData()[oldname].(*InMemoryFile) delete(m.getData(), oldname) + file.name = newname + m.getData()[newname] = file + m.registerWithParent(file) m.unlock() m.rlock() } else {