From fafd4f85132bfa97195b8efc2a0a7524fae7d52c Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 15 Jul 2022 10:38:01 +0800 Subject: [PATCH 1/7] =?UTF-8?q?:sparkles:=20=E8=B5=84=E6=BA=90=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E9=87=8D=E5=91=BD=E5=90=8D=20https://github.com/siyua?= =?UTF-8?q?n-note/siyuan/issues/3454?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/asset.go | 14 ++++++++++++ kernel/api/router.go | 1 + kernel/model/assets.go | 48 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/kernel/api/asset.go b/kernel/api/asset.go index 0d4d0cdf4..4ec39f3eb 100644 --- a/kernel/api/asset.go +++ b/kernel/api/asset.go @@ -28,6 +28,20 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) +func renameAsset(c *gin.Context) { + ret := gulu.Ret.NewResult() + defer c.JSON(http.StatusOK, ret) + + arg, ok := util.JsonArg(c, ret) + if !ok { + return + } + + oldName := arg["oldName"].(string) + newName := arg["newName"].(string) + model.RenameAsset(oldName, newName) +} + func getDocImageAssets(c *gin.Context) { ret := gulu.Ret.NewResult() defer c.JSON(http.StatusOK, ret) diff --git a/kernel/api/router.go b/kernel/api/router.go index 8c9a32ef9..370dcf34c 100644 --- a/kernel/api/router.go +++ b/kernel/api/router.go @@ -185,6 +185,7 @@ func ServeAPI(ginServer *gin.Engine) { ginServer.Handle("POST", "/api/asset/removeUnusedAsset", model.CheckAuth, model.CheckReadonly, removeUnusedAsset) ginServer.Handle("POST", "/api/asset/removeUnusedAssets", model.CheckAuth, model.CheckReadonly, removeUnusedAssets) ginServer.Handle("POST", "/api/asset/getDocImageAssets", model.CheckAuth, model.CheckReadonly, getDocImageAssets) + ginServer.Handle("POST", "/api/asset/renameAsset", model.CheckAuth, model.CheckReadonly, renameAsset) ginServer.Handle("POST", "/api/export/batchExportMd", model.CheckAuth, batchExportMd) ginServer.Handle("POST", "/api/export/exportMd", model.CheckAuth, exportMd) diff --git a/kernel/model/assets.go b/kernel/model/assets.go index 05474f7b1..f7697e7cd 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -34,6 +34,7 @@ import ( "github.com/88250/gulu" "github.com/88250/lute/ast" "github.com/88250/lute/parse" + "github.com/88250/protyle" "github.com/gabriel-vasile/mimetype" "github.com/siyuan-note/filelock" "github.com/siyuan-note/httpclient" @@ -443,6 +444,53 @@ func RemoveUnusedAsset(p string) (ret string) { return } +func RenameAsset(oldName, newName string) { + util.PushEndlessProgress(Conf.Language(110)) + defer util.PushClearProgress() + + notebooks, err := ListNotebooks() + if nil != err { + return + } + + luteEngine := NewLute() + for _, notebook := range notebooks { + pages := pagedPaths(filepath.Join(util.DataDir, notebook.ID), 32) + for _, paths := range pages { + for _, treeAbsPath := range paths { + data, err := filelock.NoLockFileRead(treeAbsPath) + if nil != err { + util.LogErrorf("get data [path=%s] failed: %s", treeAbsPath, err) + return + } + + if !bytes.Contains(data, []byte(oldName)) { + return + } + + data = bytes.Replace(data, []byte(oldName), []byte(newName), -1) + if err = filelock.NoLockFileWrite(treeAbsPath, data); nil != err { + util.LogErrorf("write data [path=%s] failed: %s", treeAbsPath, err) + return + } + + tree, err := protyle.ParseJSONWithoutFix(luteEngine, data) + if nil != err { + util.LogErrorf("parse json to tree [%s] failed: %s", treeAbsPath, err) + return + } + + treenode.ReindexBlockTree(tree) + sql.UpsertTreeQueue(tree) + + util.PushEndlessProgress(fmt.Sprintf(Conf.Language(111), tree.Root.IALAttr("title"))) + } + } + } + + IncSync() +} + func UnusedAssets() (ret []string) { ret = []string{} From 075a6af7ad3a04f16bbdd36abb012655c94a7c67 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 15 Jul 2022 10:52:02 +0800 Subject: [PATCH 2/7] =?UTF-8?q?:sparkles:=20=E8=B5=84=E6=BA=90=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E9=87=8D=E5=91=BD=E5=90=8D=20https://github.com/siyua?= =?UTF-8?q?n-note/siyuan/issues/3454?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20200924100744-br924ar.sy | 68 +++++++++---------- .../20200915214115-42b8zma.sy | 42 +++++++++++- .../20211226123038-4umgpxy.sy | 52 ++++++++++++-- kernel/api/asset.go | 4 +- kernel/model/assets.go | 22 +++--- 5 files changed, 134 insertions(+), 54 deletions(-) diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100744-br924ar.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100744-br924ar.sy index b8fb93db4..f3e7da86f 100644 --- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100744-br924ar.sy +++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100744-br924ar.sy @@ -5,7 +5,7 @@ "id": "20200924100744-br924ar", "title": "Assets", "type": "doc", - "updated": "20220715092808" + "updated": "20220715105117" }, "Children": [ { @@ -625,7 +625,7 @@ "ListData": {}, "Properties": { "id": "20220503122349-o26mvnq", - "updated": "20220715092808" + "updated": "20220715105117" }, "Children": [ { @@ -650,23 +650,7 @@ "Children": [ { "Type": "NodeText", - "Data": "When deleting the notebook, in order to ensure that cross-notebook asset references work properly, the " - }, - { - "Type": "NodeText", - "Data": "assets" - }, - { - "Type": "NodeText", - "Data": " under the notebook will be copied to the global " - }, - { - "Type": "NodeText", - "Data": "assets" - }, - { - "Type": "NodeText", - "Data": " in batches" + "Data": "When deleting the notebook, in order to ensure that cross-notebook asset references work properly, the assets under the notebook will be copied to the global assets in batches" } ] } @@ -694,19 +678,7 @@ "Children": [ { "Type": "NodeText", - "Data": "Does not support viewing notebook-level " - }, - { - "Type": "NodeText", - "Data": "assets" - }, - { - "Type": "NodeText", - "Data": " history in " - }, - { - "Type": "NodeText", - "Data": "data history" + "Data": "Does not support viewing notebook-level assets history in data history" } ] } @@ -721,7 +693,7 @@ }, "Properties": { "id": "20220715092756-f5azf15", - "updated": "20220715092808" + "updated": "20220715105117" }, "Children": [ { @@ -729,7 +701,7 @@ "Type": "NodeParagraph", "Properties": { "id": "20220715092756-4bzibji", - "updated": "20220715092808" + "updated": "20220715105117" }, "Children": [ { @@ -755,6 +727,34 @@ ] } ] + }, + { + "ID": "20220715105056-8d652vx", + "Type": "NodeListItem", + "ListData": { + "BulletChar": 42, + "Marker": "Kg==" + }, + "Properties": { + "id": "20220715105056-8d652vx", + "updated": "20220715105100" + }, + "Children": [ + { + "ID": "20220715105056-a6p3fg7", + "Type": "NodeParagraph", + "Properties": { + "id": "20220715105056-a6p3fg7", + "updated": "20220715105100" + }, + "Children": [ + { + "Type": "NodeText", + "Data": "Dose not support rename" + } + ] + } + ] } ] } diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200915214115-42b8zma.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200915214115-42b8zma.sy index 5d5c9916a..2b98cfa98 100644 --- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200915214115-42b8zma.sy +++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200915214115-42b8zma.sy @@ -5,7 +5,7 @@ "id": "20200915214115-42b8zma", "title": "资源文件", "type": "doc", - "updated": "20220715092726" + "updated": "20220715105016" }, "Children": [ { @@ -547,7 +547,7 @@ "ListData": {}, "Properties": { "id": "20220503121213-afjyt05", - "updated": "20220715092726" + "updated": "20220715105016" }, "Children": [ { @@ -572,7 +572,15 @@ "Children": [ { "Type": "NodeText", - "Data": "删除该笔记本时,为保证跨笔记本资源文件引用正常工作,该笔记本下的资源文件会被批量复制到全局 assets 中" + "Data": "删除该笔记本时,为保证跨笔记本资源文件引用正常工作,该笔记本下的资源文件会被批量复制到全局 " + }, + { + "Type": "NodeText", + "Data": "assets" + }, + { + "Type": "NodeText", + "Data": " 中" } ] } @@ -661,6 +669,34 @@ ] } ] + }, + { + "ID": "20220715105014-5jfe0bz", + "Type": "NodeListItem", + "ListData": { + "BulletChar": 42, + "Marker": "Kg==" + }, + "Properties": { + "id": "20220715105014-5jfe0bz", + "updated": "20220715105016" + }, + "Children": [ + { + "ID": "20220715105014-3r1es71", + "Type": "NodeParagraph", + "Properties": { + "id": "20220715105014-3r1es71", + "updated": "20220715105016" + }, + "Children": [ + { + "Type": "NodeText", + "Data": "不支持重命名" + } + ] + } + ] } ] } diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123038-4umgpxy.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123038-4umgpxy.sy index 7642567f9..7ad7de34d 100644 --- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123038-4umgpxy.sy +++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123038-4umgpxy.sy @@ -4,7 +4,7 @@ "Properties": { "id": "20211226123038-4umgpxy", "title": "資料文件", - "updated": "20220715092951" + "updated": "20220715105038" }, "Children": [ { @@ -554,7 +554,7 @@ "ListData": {}, "Properties": { "id": "20220503122338-jmr7c2k", - "updated": "20220715092938" + "updated": "20220715105038" }, "Children": [ { @@ -579,7 +579,15 @@ "Children": [ { "Type": "NodeText", - "Data": "刪除該筆記本時,為保證跨筆記本資料文件引用正常工作,該筆記本下的資料文件會被批量複製到全局 assets 中" + "Data": "刪除該筆記本時,為保證跨筆記本資料文件引用正常工作,該筆記本下的資料文件會被批量複製到全局 " + }, + { + "Type": "NodeText", + "Data": "assets" + }, + { + "Type": "NodeText", + "Data": " 中" } ] } @@ -607,7 +615,15 @@ "Children": [ { "Type": "NodeText", - "Data": "不支持在數據歷史中查看筆記本級資料文件歷史" + "Data": "不支持在" + }, + { + "Type": "NodeText", + "Data": "數據歷史" + }, + { + "Type": "NodeText", + "Data": "中查看筆記本級資料文件歷史" } ] } @@ -660,6 +676,34 @@ ] } ] + }, + { + "ID": "20220715105038-bwu5wmg", + "Type": "NodeListItem", + "ListData": { + "BulletChar": 42, + "Marker": "Kg==" + }, + "Properties": { + "id": "20220715105038-bwu5wmg", + "updated": "20220715105038" + }, + "Children": [ + { + "ID": "20220715105038-mmy9v15", + "Type": "NodeParagraph", + "Properties": { + "id": "20220715105038-mmy9v15", + "updated": "20220715105038" + }, + "Children": [ + { + "Type": "NodeText", + "Data": "不支持重命名" + } + ] + } + ] } ] } diff --git a/kernel/api/asset.go b/kernel/api/asset.go index 4ec39f3eb..2482fc39c 100644 --- a/kernel/api/asset.go +++ b/kernel/api/asset.go @@ -37,9 +37,9 @@ func renameAsset(c *gin.Context) { return } - oldName := arg["oldName"].(string) + oldPath := arg["oldPath"].(string) newName := arg["newName"].(string) - model.RenameAsset(oldName, newName) + model.RenameAsset(oldPath, newName) } func getDocImageAssets(c *gin.Context) { diff --git a/kernel/model/assets.go b/kernel/model/assets.go index f7697e7cd..3029aba1e 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -444,7 +444,7 @@ func RemoveUnusedAsset(p string) (ret string) { return } -func RenameAsset(oldName, newName string) { +func RenameAsset(oldPath, newName string) { util.PushEndlessProgress(Conf.Language(110)) defer util.PushClearProgress() @@ -458,25 +458,25 @@ func RenameAsset(oldName, newName string) { pages := pagedPaths(filepath.Join(util.DataDir, notebook.ID), 32) for _, paths := range pages { for _, treeAbsPath := range paths { - data, err := filelock.NoLockFileRead(treeAbsPath) - if nil != err { - util.LogErrorf("get data [path=%s] failed: %s", treeAbsPath, err) + data, readErr := filelock.NoLockFileRead(treeAbsPath) + if nil != readErr { + util.LogErrorf("get data [path=%s] failed: %s", treeAbsPath, readErr) return } - if !bytes.Contains(data, []byte(oldName)) { + if !bytes.Contains(data, []byte(oldPath)) { return } - data = bytes.Replace(data, []byte(oldName), []byte(newName), -1) - if err = filelock.NoLockFileWrite(treeAbsPath, data); nil != err { - util.LogErrorf("write data [path=%s] failed: %s", treeAbsPath, err) + data = bytes.Replace(data, []byte(oldPath), []byte(newName), -1) + if writeErr := filelock.NoLockFileWrite(treeAbsPath, data); nil != writeErr { + util.LogErrorf("write data [path=%s] failed: %s", treeAbsPath, writeErr) return } - tree, err := protyle.ParseJSONWithoutFix(luteEngine, data) - if nil != err { - util.LogErrorf("parse json to tree [%s] failed: %s", treeAbsPath, err) + tree, parseErr := protyle.ParseJSONWithoutFix(luteEngine, data) + if nil != parseErr { + util.LogErrorf("parse json to tree [%s] failed: %s", treeAbsPath, parseErr) return } From 437ab17b26809a63c500e168be78e0b59c310671 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 15 Jul 2022 10:55:45 +0800 Subject: [PATCH 3/7] =?UTF-8?q?:sparkles:=20=E8=B5=84=E6=BA=90=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E9=87=8D=E5=91=BD=E5=90=8D=20https://github.com/siyua?= =?UTF-8?q?n-note/siyuan/issues/3454?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/assets.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/model/assets.go b/kernel/model/assets.go index 3029aba1e..0e7812f65 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -453,6 +453,8 @@ func RenameAsset(oldPath, newName string) { return } + newPath := util.AssetName(newName) + luteEngine := NewLute() for _, notebook := range notebooks { pages := pagedPaths(filepath.Join(util.DataDir, notebook.ID), 32) @@ -468,7 +470,7 @@ func RenameAsset(oldPath, newName string) { return } - data = bytes.Replace(data, []byte(oldPath), []byte(newName), -1) + data = bytes.Replace(data, []byte(oldPath), []byte(newPath), -1) if writeErr := filelock.NoLockFileWrite(treeAbsPath, data); nil != writeErr { util.LogErrorf("write data [path=%s] failed: %s", treeAbsPath, writeErr) return @@ -488,6 +490,10 @@ func RenameAsset(oldPath, newName string) { } } + if err = os.Rename(filepath.Join(util.DataDir, oldPath), filepath.Join(util.DataDir, newPath)); nil != err { + util.LogErrorf("rename asset [%s] failed: %s", oldPath, err) + } + IncSync() } From f29bf51c12e3b7fcb5776c9bb5964358a9c76ba2 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 15 Jul 2022 11:08:48 +0800 Subject: [PATCH 4/7] =?UTF-8?q?:sparkles:=20=E8=B5=84=E6=BA=90=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E9=87=8D=E5=91=BD=E5=90=8D=20https://github.com/siyua?= =?UTF-8?q?n-note/siyuan/issues/3454?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/assets.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/model/assets.go b/kernel/model/assets.go index 0e7812f65..93236525d 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -495,6 +495,10 @@ func RenameAsset(oldPath, newName string) { } IncSync() + + util.PushEndlessProgress(Conf.Language(113)) + sql.WaitForWritingDatabase() + util.ReloadUI() } func UnusedAssets() (ret []string) { From f39750e39357fa9f4844365ab6db798c1eb14d03 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 15 Jul 2022 11:11:54 +0800 Subject: [PATCH 5/7] =?UTF-8?q?:sparkles:=20=E8=B5=84=E6=BA=90=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E9=87=8D=E5=91=BD=E5=90=8D=20https://github.com/siyua?= =?UTF-8?q?n-note/siyuan/issues/3454?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/assets.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kernel/model/assets.go b/kernel/model/assets.go index 93236525d..2973e0320 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -453,8 +453,16 @@ func RenameAsset(oldPath, newName string) { return } - newPath := util.AssetName(newName) + newName = strings.TrimSpace(newName) + newName = gulu.Str.RemoveInvisible(newName) + if path.Base(oldPath) == newName { + return + } + if "" == newName { + return + } + newPath := util.AssetName(newName) luteEngine := NewLute() for _, notebook := range notebooks { pages := pagedPaths(filepath.Join(util.DataDir, notebook.ID), 32) From 14c023477c075a564ad6086b2195d64c2598e937 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 15 Jul 2022 11:15:02 +0800 Subject: [PATCH 6/7] =?UTF-8?q?:sparkles:=20=E8=B5=84=E6=BA=90=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E9=87=8D=E5=91=BD=E5=90=8D=20https://github.com/siyua?= =?UTF-8?q?n-note/siyuan/issues/3454?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/asset.go | 8 +++++++- kernel/model/assets.go | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/kernel/api/asset.go b/kernel/api/asset.go index 2482fc39c..4d3a80d04 100644 --- a/kernel/api/asset.go +++ b/kernel/api/asset.go @@ -39,7 +39,13 @@ func renameAsset(c *gin.Context) { oldPath := arg["oldPath"].(string) newName := arg["newName"].(string) - model.RenameAsset(oldPath, newName) + err := model.RenameAsset(oldPath, newName) + if nil != err { + ret.Code = -1 + ret.Msg = err.Error() + ret.Data = map[string]interface{}{"closeTimeout": 5000} + return + } } func getDocImageAssets(c *gin.Context) { diff --git a/kernel/model/assets.go b/kernel/model/assets.go index 2973e0320..04e0ba25a 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -444,7 +444,7 @@ func RemoveUnusedAsset(p string) (ret string) { return } -func RenameAsset(oldPath, newName string) { +func RenameAsset(oldPath, newName string) (err error) { util.PushEndlessProgress(Conf.Language(110)) defer util.PushClearProgress() @@ -462,6 +462,11 @@ func RenameAsset(oldPath, newName string) { return } + if !gulu.File.IsValidFilename(newName) { + err = errors.New(Conf.Language(151)) + return + } + newPath := util.AssetName(newName) luteEngine := NewLute() for _, notebook := range notebooks { @@ -471,6 +476,7 @@ func RenameAsset(oldPath, newName string) { data, readErr := filelock.NoLockFileRead(treeAbsPath) if nil != readErr { util.LogErrorf("get data [path=%s] failed: %s", treeAbsPath, readErr) + err = readErr return } @@ -481,12 +487,14 @@ func RenameAsset(oldPath, newName string) { data = bytes.Replace(data, []byte(oldPath), []byte(newPath), -1) if writeErr := filelock.NoLockFileWrite(treeAbsPath, data); nil != writeErr { util.LogErrorf("write data [path=%s] failed: %s", treeAbsPath, writeErr) + err = writeErr return } tree, parseErr := protyle.ParseJSONWithoutFix(luteEngine, data) if nil != parseErr { util.LogErrorf("parse json to tree [%s] failed: %s", treeAbsPath, parseErr) + err = parseErr return } @@ -500,6 +508,7 @@ func RenameAsset(oldPath, newName string) { if err = os.Rename(filepath.Join(util.DataDir, oldPath), filepath.Join(util.DataDir, newPath)); nil != err { util.LogErrorf("rename asset [%s] failed: %s", oldPath, err) + return } IncSync() @@ -507,6 +516,7 @@ func RenameAsset(oldPath, newName string) { util.PushEndlessProgress(Conf.Language(113)) sql.WaitForWritingDatabase() util.ReloadUI() + return } func UnusedAssets() (ret []string) { From ba329cb252fd7eee4f51361078692c47a73810fa Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 15 Jul 2022 11:18:35 +0800 Subject: [PATCH 7/7] =?UTF-8?q?:sparkles:=20=E8=B5=84=E6=BA=90=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E9=87=8D=E5=91=BD=E5=90=8D=20https://github.com/siyua?= =?UTF-8?q?n-note/siyuan/issues/3454?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/assets.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/model/assets.go b/kernel/model/assets.go index 04e0ba25a..6cc0978ab 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -468,6 +468,11 @@ func RenameAsset(oldPath, newName string) (err error) { } newPath := util.AssetName(newName) + if err = gulu.File.Copy(filepath.Join(util.DataDir, oldPath), filepath.Join(util.DataDir, newPath)); nil != err { + util.LogErrorf("copy asset [%s] failed: %s", oldPath, err) + return + } + luteEngine := NewLute() for _, notebook := range notebooks { pages := pagedPaths(filepath.Join(util.DataDir, notebook.ID), 32) @@ -506,11 +511,6 @@ func RenameAsset(oldPath, newName string) (err error) { } } - if err = os.Rename(filepath.Join(util.DataDir, oldPath), filepath.Join(util.DataDir, newPath)); nil != err { - util.LogErrorf("rename asset [%s] failed: %s", oldPath, err) - return - } - IncSync() util.PushEndlessProgress(Conf.Language(113))