Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve renaming assets https://github.com/siyuan-note/siyuan/issues/14467

Danielf43699b2c430
diff --git a/kernel/model/assets.go b/kernel/model/assets.go
index 0405b3f651..d0e8faab02 100644
--- a/kernel/model/assets.go
+++ b/kernel/model/assets.go
@@ -649,9 +649,16 @@ func RenameAsset(oldPath, newName string) (newPath string, err error) {
}
newName = util.AssetName(newName + filepath.Ext(oldPath))
- newPath = "assets/" + newName
- if err = filelock.Copy(filepath.Join(util.DataDir, oldPath), filepath.Join(util.DataDir, newPath)); err != nil {
- logging.LogErrorf("copy asset [%s] failed: %s", oldPath, err)
+ parentDir := path.Dir(oldPath)
+ newPath = path.Join(parentDir, newName)
+ oldAbsPath, getErr := GetAssetAbsPath(oldPath)
+ if getErr != nil {
+ logging.LogErrorf("get asset [%s] abs path failed: %s", oldPath, getErr)
+ return
+ }
+ newAbsPath := filepath.Join(filepath.Dir(oldAbsPath), newName)
+ if err = filelock.Copy(oldAbsPath, newAbsPath); err != nil {
+ logging.LogErrorf("copy asset [%s] failed: %s", oldAbsPath, err)
return
}