From f5d2472495e40efb03897d1b9d3e9096599c7e53 Mon Sep 17 00:00:00 2001 From: spf13 Date: Fri, 31 Oct 2014 23:38:54 -0400 Subject: [PATCH] Adding proper open support for memfile --- memfile.go | 5 +++++ memmap.go | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/memfile.go b/memfile.go index ceaf528..fcf80d2 100644 --- a/memfile.go +++ b/memfile.go @@ -45,6 +45,11 @@ type InMemoryFile struct { func MemFileCreate(name string) *InMemoryFile { return &InMemoryFile{name: name, mode: os.ModeTemporary, modtime: time.Now()} } + +func (f *InMemoryFile) Open() error { + atomic.StoreInt64(&f.at, 0) + f.closed = false + return nil } func (f *InMemoryFile) Close() error { diff --git a/memmap.go b/memmap.go index af3c653..d820502 100644 --- a/memmap.go +++ b/memmap.go @@ -152,9 +152,13 @@ func (m *MemMapFs) MkdirAll(path string, perm os.FileMode) error { func (m *MemMapFs) Open(name string) (File, error) { m.rlock() f, ok := m.getData()[name] - m.runlock() + ff, ok := f.(*InMemoryFile) + if ok { + ff.Open() + } + m.runlock() + if ok { - f.Seek(0, 0) return f, nil } else { return nil, ErrFileNotFound