From e536f5d4b62ab75c1cf659bcc4fce81caa52166a Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 26 Sep 2022 20:20:50 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E6=97=A0=E6=B3=95=E6=8F=92=E5=85=A5?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=96=87=E4=BB=B6=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20Fix=20https://github.com/siyuan-note/siyuan/issues/5971?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/cache/asset.go | 3 +++ kernel/model/upload.go | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/kernel/cache/asset.go b/kernel/cache/asset.go index d96f46ee0..0ed480d8b 100644 --- a/kernel/cache/asset.go +++ b/kernel/cache/asset.go @@ -45,6 +45,9 @@ func LoadAssets() { assets := filepath.Join(util.DataDir, "assets") filepath.Walk(assets, func(path string, info fs.FileInfo, err error) error { + if nil == info { + return err + } if info.IsDir() { if strings.HasPrefix(info.Name(), ".") { return filepath.SkipDir diff --git a/kernel/model/upload.go b/kernel/model/upload.go index fd4ce9860..41d34ce7c 100644 --- a/kernel/model/upload.go +++ b/kernel/model/upload.go @@ -45,6 +45,12 @@ func InsertLocalAssets(id string, assetPaths []string) (succMap map[string]inter docDirLocalPath := filepath.Join(util.DataDir, bt.BoxID, path.Dir(bt.Path)) assets := getAssetsDir(filepath.Join(util.DataDir, bt.BoxID), docDirLocalPath) + if !gulu.File.IsExist(assets) { + if err = os.MkdirAll(assets, 0755); nil != err { + return + } + } + for _, p := range assetPaths { fName := filepath.Base(p) fName = util.FilterUploadFileName(fName) @@ -124,7 +130,9 @@ func Upload(c *gin.Context) { if nil != form.Value["assetsDirPath"] { assetsDirPath = form.Value["assetsDirPath"][0] assetsDirPath = filepath.Join(util.DataDir, assetsDirPath) - if err := os.MkdirAll(assetsDirPath, 0755); nil != err { + } + if !gulu.File.IsExist(assetsDirPath) { + if err = os.MkdirAll(assetsDirPath, 0755); nil != err { ret.Code = -1 ret.Msg = err.Error() return