From 6a85c9a7c48084c2b7b04a1af7f6443ed22a57b7 Mon Sep 17 00:00:00 2001 From: veypi Date: Wed, 30 Oct 2024 17:06:23 +0800 Subject: [PATCH] feat: fs mkdirall --- oa/libs/webdav/file.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/oa/libs/webdav/file.go b/oa/libs/webdav/file.go index 3cd19ff..df486bc 100644 --- a/oa/libs/webdav/file.go +++ b/oa/libs/webdav/file.go @@ -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