Skip to content

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

:bug: Improve importing .sy.zip https://github.com/siyuan-note/siyuan/issues/12825

Daniel5efce9b33e8d
diff --git a/kernel/model/import.go b/kernel/model/import.go
index e20c9dffab..f3f7104c9c 100644
--- a/kernel/model/import.go
+++ b/kernel/model/import.go
@@ -208,6 +208,12 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
})
}
+ var replacements []string
+ for oldID, newID := range blockIDs {
+ replacements = append(replacements, oldID, newID)
+ }
+ blockIDReplacer := strings.NewReplacer(replacements...)
+
// 将关联的数据库文件移动到 data/storage/av/ 下
storage := filepath.Join(unzipRootPath, "storage")
storageAvDir := filepath.Join(storage, "av")
@@ -242,9 +248,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
for oldAvID, newAvID := range avIDs {
newData = bytes.ReplaceAll(newData, []byte(oldAvID), []byte(newAvID))
}
- for oldID, newID := range blockIDs {
- newData = bytes.ReplaceAll(newData, []byte(oldID), []byte(newID))
- }
+ newData = []byte(blockIDReplacer.Replace(string(newData)))
if !bytes.Equal(data, newData) {
if writeErr := os.WriteFile(oldPath, newData, 0644); nil != writeErr {
logging.LogErrorf("write av file [%s] failed: %s", oldPath, writeErr)