From c6c92c3af0ffd3c7e65ca47b8dedb56160769375 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sat, 11 Feb 2023 11:59:54 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=95=B0=E6=8D=AE=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=8F=91=E7=94=9F=E5=86=B2=E7=AA=81=E6=97=B6=E5=9C=A8=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E4=B8=8A=E8=BF=9B=E8=A1=8C=E6=8F=90=E9=86=92=20https:?= =?UTF-8?q?//github.com/siyuan-note/siyuan/issues/7332?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/repository.go | 71 ++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/kernel/model/repository.go b/kernel/model/repository.go index a2306b585..18190855a 100644 --- a/kernel/model/repository.go +++ b/kernel/model/repository.go @@ -1071,35 +1071,38 @@ func syncRepo(exit, byHand bool) (err error) { func processSyncMergeResult(exit, byHand bool, start time.Time, mergeResult *dejavu.MergeResult) { //logSyncMergeResult(mergeResult) - if 0 < len(mergeResult.Conflicts) && Conf.Sync.GenerateConflictDoc { - // 云端同步发生冲突时生成副本 https://github.com/siyuan-note/siyuan/issues/5687 + if 0 < len(mergeResult.Conflicts) { + luteEngine := util.NewLute() + if Conf.Sync.GenerateConflictDoc { + // 云端同步发生冲突时生成副本 https://github.com/siyuan-note/siyuan/issues/5687 + + for _, file := range mergeResult.Conflicts { + if !strings.HasSuffix(file.Path, ".sy") { + continue + } + + parts := strings.Split(file.Path[1:], "/") + if 2 > len(parts) { + continue + } + boxID := parts[0] + + absPath := filepath.Join(util.TempDir, "repo", "sync", "conflicts", mergeResult.Time.Format("2006-01-02-150405"), file.Path) + tree, loadTreeErr := loadTree(absPath, luteEngine) + if nil != loadTreeErr { + logging.LogErrorf("load conflicted file [%s] failed: %s", absPath, loadTreeErr) + continue + } + tree.Box = boxID + tree.Path = strings.TrimPrefix(file.Path, "/"+boxID) + + resetTree(tree, "Conflicted") + createTreeTx(tree) + } + } historyDir := filepath.Join(util.HistoryDir, mergeResult.Time.Format("2006-01-02-150405")+"-sync") - luteEngine := util.NewLute() - for _, file := range mergeResult.Conflicts { - if !strings.HasSuffix(file.Path, ".sy") { - continue - } - - parts := strings.Split(file.Path[1:], "/") - if 2 > len(parts) { - continue - } - boxID := parts[0] - - absPath := filepath.Join(util.TempDir, "repo", "sync", "conflicts", mergeResult.Time.Format("2006-01-02-150405"), file.Path) - tree, loadTreeErr := loadTree(absPath, luteEngine) - if nil != loadTreeErr { - logging.LogErrorf("load conflicted file [%s] failed: %s", absPath, loadTreeErr) - continue - } - tree.Box = boxID - tree.Path = strings.TrimPrefix(file.Path, "/"+boxID) - - resetTree(tree, "Conflicted") - createTreeTx(tree) - indexHistoryDir(filepath.Base(historyDir), luteEngine) - } + indexHistoryDir(filepath.Base(historyDir), luteEngine) } if 1 > len(mergeResult.Upserts) && 1 > len(mergeResult.Removes) && 1 > len(mergeResult.Conflicts) { // 没有数据变更 @@ -1173,8 +1176,18 @@ func processSyncMergeResult(exit, byHand bool, start time.Time, mergeResult *dej util.PushStatusBar(fmt.Sprintf(Conf.Language(149), elapsed.Seconds())) if 0 < len(mergeResult.Conflicts) { - // 数据同步发生冲突时在界面上进行提醒 https://github.com/siyuan-note/siyuan/issues/7332 - util.PushMsg(Conf.Language(108), 7000) + syConflict := false + for _, file := range mergeResult.Conflicts { + if strings.HasSuffix(file.Path, ".sy") { + syConflict = true + break + } + } + + if syConflict { + // 数据同步发生冲突时在界面上进行提醒 https://github.com/siyuan-note/siyuan/issues/7332 + util.PushMsg(Conf.Language(108), 7000) + } } }() }