mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-24 02:20:13 +01:00
This commit is contained in:
parent
fafd4f8513
commit
075a6af7ad
5 changed files with 134 additions and 54 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue