Skip to content

Commit

Permalink
✨ 资源文件重命名 #3454
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jul 15, 2022
1 parent 075a6af commit 437ab17
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion kernel/model/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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()
}

Expand Down

0 comments on commit 437ab17

Please sign in to comment.