pkger/fs/memware/create.go

41 lines
608 B
Go
Raw Normal View History

2019-09-02 00:58:20 +03:00
package memware
2019-09-01 00:00:24 +03:00
import (
"path/filepath"
"time"
"github.com/markbates/pkger/fs"
)
2019-09-02 00:54:05 +03:00
func (fx *Warehouse) Create(name string) (fs.File, error) {
2019-09-01 00:00:24 +03:00
pt, err := fx.Parse(name)
if err != nil {
return nil, err
}
her, err := fx.Info(pt.Pkg)
if err != nil {
return nil, err
}
f := &File{
path: pt,
her: her,
info: &fs.FileInfo{
Details: fs.Details{
Name: pt.Name,
2019-09-01 05:45:22 +03:00
Mode: 0644,
2019-09-01 00:00:24 +03:00
ModTime: fs.ModTime(time.Now()),
},
},
fs: fx,
}
fx.files.Store(pt, f)
dir := filepath.Dir(pt.Name)
if err := fx.MkdirAll(dir, 0644); err != nil {
return nil, err
}
return f, nil
}