Use filepath.Abs to interpret relative file paths

This commit is contained in:
Will Plusnick 2015-12-01 20:55:00 -06:00
parent f85f3b3779
commit 77f1ec73f1
1 changed files with 1 additions and 9 deletions

View File

@ -88,6 +88,7 @@ func (MemMapFs) Name() string { return "MemMapFS" }
func (m *MemMapFs) Create(name string) (File, error) { func (m *MemMapFs) Create(name string) (File, error) {
m.lock() m.lock()
name, _ = filepath.Abs(name)
file := MemFileCreate(name) file := MemFileCreate(name)
m.getData()[name] = file m.getData()[name] = file
m.registerWithParent(file) m.registerWithParent(file)
@ -141,15 +142,6 @@ func (m *MemMapFs) registerWithParent(f File) {
} }
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)
} }