Adding proper open support for memfile

This commit is contained in:
spf13 2014-10-31 23:38:54 -04:00
parent 0c3b992fe6
commit f5d2472495
2 changed files with 11 additions and 2 deletions

View File

@ -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 {

View File

@ -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