pkger/dir.go

57 lines
820 B
Go
Raw Normal View History

2019-08-09 04:51:58 +03:00
package pkger
import (
"os"
"path/filepath"
2019-08-09 22:30:12 +03:00
"time"
2019-08-09 04:51:58 +03:00
)
2019-08-09 05:35:01 +03:00
func MkdirAll(p string, perm os.FileMode) error {
path, err := Parse(p)
2019-08-09 04:51:58 +03:00
if err != nil {
return err
}
root := path.Name
2019-08-09 22:30:12 +03:00
cur, err := Stat()
if err != nil {
return err
}
2019-08-09 04:51:58 +03:00
for root != "" && root != "/" {
pt := Path{
Pkg: path.Pkg,
Name: root,
}
2019-08-09 22:30:12 +03:00
if _, ok := filesCache.Load(pt); ok {
root = filepath.Dir(root)
continue
}
f := &File{
path: pt,
her: cur,
info: &FileInfo{
name: pt.Name,
mode: 0666,
modTime: time.Now(),
virtual: true,
},
}
filesCache.Store(pt, f)
2019-08-09 04:51:58 +03:00
if err != nil {
return err
}
f.info.isDir = true
f.info.mode = perm
f.info.virtual = true
if err := f.Close(); err != nil {
return err
}
2019-08-09 05:35:01 +03:00
filesCache.Store(pt, f)
2019-08-09 04:51:58 +03:00
root = filepath.Dir(root)
}
return nil
}