From 1dd88f818f70c869a45d6ef6359f65fe0107b77a Mon Sep 17 00:00:00 2001 From: Martin Bertschler Date: Sat, 7 Nov 2015 01:00:03 +0100 Subject: [PATCH] Fix a bug that happens when the parent is the "." file. --- memmap.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/memmap.go b/memmap.go index 2046063..f2e9425 100644 --- a/memmap.go +++ b/memmap.go @@ -130,16 +130,26 @@ func (m *MemMapFs) registerWithParent(f File) { pdir := filepath.Dir(path.Clean(f.Name())) err := m.lockfreeMkdir(pdir, 0777) if err != nil { - log.Println("Mkdir error:", err) + //log.Println("Mkdir error:", err) return } parent, err = m.lockfreeOpen(pdir) if err != nil { - log.Println("Open after Mkdir error:", err) + //log.Println("Open after Mkdir error:", err) return } } pmem := parent.(*InMemoryFile) + + // TODO(mbertschler): memDir is only nil when it was not made with Mkdir + // or lockfreeMkdir. In this case the parent is also not a real directory. + // This currently only happens for the file ".". + // This is a quick hack to make the library usable with relative paths. + if pmem.memDir == nil { + pmem.dir = true + pmem.memDir = &MemDirMap{} + } + pmem.memDir.Add(f) }