Fix a bug that happens when the parent is the "." file.

This commit is contained in:
Martin Bertschler 2015-11-07 01:00:03 +01:00 committed by Bjørn Erik Pedersen
parent 1407a13a63
commit 0a58b8245b
1 changed files with 12 additions and 2 deletions

View File

@ -130,16 +130,26 @@ func (m *MemMapFs) registerWithParent(f File) {
pdir := filepath.Dir(path.Clean(f.Name())) pdir := filepath.Dir(path.Clean(f.Name()))
err := m.lockfreeMkdir(pdir, 0777) err := m.lockfreeMkdir(pdir, 0777)
if err != nil { if err != nil {
log.Println("Mkdir error:", err) //log.Println("Mkdir error:", err)
return return
} }
parent, err = m.lockfreeOpen(pdir) parent, err = m.lockfreeOpen(pdir)
if err != nil { if err != nil {
log.Println("Open after Mkdir error:", err) //log.Println("Open after Mkdir error:", err)
return return
} }
} }
pmem := parent.(*InMemoryFile) 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) pmem.memDir.Add(f)
} }