🎨 导出导入 .sy.zip 保持自定义排序 Fix https://github.com/siyuan-note/siyuan/issues/5939
This commit is contained in:
parent
b49f477f59
commit
11aa06038b
1 changed files with 45 additions and 0 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue