From 5efce9b33e8d86807acd5283d25578932d417903 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Fri, 18 Oct 2024 15:01:28 +0800 Subject: [PATCH] :bug: Improve importing .sy.zip https://github.com/siyuan-note/siyuan/issues/12825 --- kernel/model/import.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kernel/model/import.go b/kernel/model/import.go index e20c9dffa..f3f7104c9 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)