mirror of https://github.com/spf13/afero.git
Adding proper open support for memfile
This commit is contained in:
parent
0c3b992fe6
commit
f5d2472495
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue