Просмотр исходного кода

:art: 数据同步发生冲突时在界面上进行提醒 https://github.com/siyuan-note/siyuan/issues/7332

Liang Ding 2 лет назад
Родитель
Сommit
c6c92c3af0
1 измененных файлов с 41 добавлено и 28 удалено
  1. 41 28
      kernel/model/repository.go

+ 41 - 28
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
-
-		historyDir := filepath.Join(util.HistoryDir, mergeResult.Time.Format("2006-01-02-150405")+"-sync")
+	if 0 < len(mergeResult.Conflicts) {
 		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
+		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)
 			}
-			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)
 		}
+
+		historyDir := filepath.Join(util.HistoryDir, mergeResult.Time.Format("2006-01-02-150405")+"-sync")
+		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)
+				}
 			}
 		}()
 	}