pkger/pkging/mem/mkdirall.go

62 lines
944 B
Go
Raw Normal View History

2019-09-03 18:29:28 +03:00
package mem
2019-09-01 00:00:24 +03:00
import (
"os"
"path/filepath"
"time"
2019-09-02 01:02:45 +03:00
"github.com/markbates/pkger/pkging"
2019-09-01 00:00:24 +03:00
)
2019-09-03 18:29:28 +03:00
func (fx *Pkger) 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 != "" {
2019-09-02 01:02:45 +03:00
pt := pkging.Path{
2019-09-01 00:00:24 +03:00
Pkg: path.Pkg,
Name: root,
}
if _, ok := fx.files.Load(pt); ok {
root = filepath.Dir(root)
if root == "/" || root == "\\" {
break
}
continue
}
f := &File{
2019-09-02 01:02:45 +03:00
pkging: fx,
path: pt,
her: cur,
info: &pkging.FileInfo{
Details: pkging.Details{
2019-09-01 00:00:24 +03:00
Name: pt.Name,
Mode: perm,
2019-09-02 01:02:45 +03:00
ModTime: pkging.ModTime(time.Now()),
2019-09-01 00:00:24 +03:00
},
},
}
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
}