Skip to content

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

:art: 导出导入 .sy.zip 保持自定义排序 Fix https://github.com/siyuan-note/siyuan/issues/5939

Liang Ding11aa06038ba9
diff --git a/kernel/model/import.go b/kernel/model/import.go
index 2513fad748..6fd686e447 100644
--- a/kernel/model/import.go
+++ b/kernel/model/import.go
@@ -174,6 +174,51 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
}
}
+ // 合并 sort.json
+ fullSortIDs := map[string]int{}
+ sortIDs := map[string]int{}
+ var sortData []byte
+ var sortErr error
+ sortPath := filepath.Join(unzipRootPath, ".siyuan", "sort.json")
+ if gulu.File.IsExist(sortPath) {
+ sortData, sortErr = filelock.NoLockFileRead(sortPath)
+ if nil != sortErr {
+ logging.LogErrorf("read import sort conf failed: %s", sortErr)
+ }
+
+ if sortErr = gulu.JSON.UnmarshalJSON(sortData, &sortIDs); nil != sortErr {
+ logging.LogErrorf("unmarshal sort conf failed: %s", sortErr)
+ }
+
+ sortPath = filepath.Join(util.DataDir, boxID, ".siyuan", "sort.json")
+ if gulu.File.IsExist(sortPath) {
+ sortData, sortErr = filelock.NoLockFileRead(sortPath)
+ if nil != sortErr {
+ logging.LogErrorf("read box sort conf failed: %s", sortErr)
+ }
+
+ if sortErr = gulu.JSON.UnmarshalJSON(sortData, &fullSortIDs); nil != sortErr {
+ logging.LogErrorf("unmarshal box sort conf failed: %s", sortErr)
+ }
+ }
+
+ for oldID, sort := range sortIDs {
+ if newID := blockIDs[oldID]; "" != newID {
+ fullSortIDs[newID] = sort
+ }
+ }
+
+ sortData, sortErr = gulu.JSON.MarshalJSON(fullSortIDs)
+ if nil != sortErr {
+ logging.LogErrorf("marshal box sort conf failed: %s", sortErr)
+ } else {
+ sortErr = filelock.NoLockFileWrite(sortPath, sortData)
+ if nil != sortErr {
+ logging.LogErrorf("write box sort conf failed: %s", sortErr)
+ }
+ }
+ }
+
// 重命名文件路径
renamePaths := map[string]string{}
filepath.Walk(unzipRootPath, func(path string, info fs.FileInfo, err error) error {