feat: fs mkdirall

v3
veypi 4 weeks ago
parent fee81d6bee
commit 6a85c9a7c4

@ -82,7 +82,7 @@ func (d Dir) Mkdir(ctx context.Context, name string, perm os.FileMode) error {
if name = d.resolve(name); name == "" {
return os.ErrNotExist
}
return os.Mkdir(name, perm)
return os.MkdirAll(name, perm)
}
func (d Dir) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (File, error) {
@ -91,6 +91,13 @@ func (d Dir) OpenFile(ctx context.Context, name string, flag int, perm os.FileMo
}
f, err := os.OpenFile(name, flag, perm)
if err != nil {
if os.IsNotExist(err) {
err = os.MkdirAll(filepath.Dir(name), 0777)
if err != nil {
return nil, err
}
return d.OpenFile(ctx, name, flag, perm)
}
return nil, err
}
return f, nil

Loading…
Cancel
Save