pkger/fs/memwh/mkdirall.go

62 lines
924 B
Go
Raw Normal View History

2019-09-02 00:50:21 +03:00
package memwh
2019-09-01 00:00:24 +03:00
import (
"os"
"path/filepath"
"time"
"github.com/markbates/pkger/fs"
)
2019-09-02 00:54:05 +03:00
func (fx *Warehouse) MkdirAll(p string, perm os.FileMode) error {
2019-09-01 00:00:24 +03:00
path, err := fx.Parse(p)
if err != nil {
return err
}
root := path.Name
cur, err := fx.Current()
if err != nil {
return err
}
for root != "" {
pt := fs.Path{
Pkg: path.Pkg,
Name: root,
}
if _, ok := fx.files.Load(pt); ok {
root = filepath.Dir(root)
if root == "/" || root == "\\" {
break
}
continue
}
f := &File{
fs: fx,
path: pt,
her: cur,
info: &fs.FileInfo{
Details: fs.Details{
Name: pt.Name,
Mode: perm,
ModTime: fs.ModTime(time.Now()),
},
},
}
if err != nil {
return err
}
f.info.Details.IsDir = true
f.info.Details.Mode = perm
if err := f.Close(); err != nil {
return err
}
fx.files.Store(pt, f)
root = filepath.Dir(root)
}
return nil
}