Преглед изворни кода

:art: 自动校验索引时排除非 id 格式的 .sy 文件 Fix https://github.com/siyuan-note/siyuan/issues/7111

Liang Ding пре 2 година
родитељ
комит
c87bb94a60
2 измењених фајлова са 23 додато и 0 уклоњено
  1. 12 0
      kernel/model/repository.go
  2. 11 0
      kernel/model/transaction.go

+ 12 - 0
kernel/model/repository.go

@@ -501,6 +501,8 @@ func InitRepoKey() (err error) {
 	return
 }
 
+var isCheckoutRepo bool
+
 func CheckoutRepo(id string) (err error) {
 	if 1 > len(Conf.Repo.Key) {
 		err = errors.New(Conf.Language(26))
@@ -523,6 +525,16 @@ func CheckoutRepo(id string) (err error) {
 	Conf.Sync.Enabled = false
 	Conf.Save()
 
+	if util.IsMutexLocked(&syncLock) {
+		err = errors.New("Sync is running, please try again later")
+		return
+	}
+
+	isCheckoutRepo = true
+	defer func() {
+		isCheckoutRepo = false
+	}()
+
 	_, _, err = repo.Checkout(id, map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBarAndProgress})
 	if nil != err {
 		util.PushClearProgress()

+ 11 - 0
kernel/model/transaction.go

@@ -1244,6 +1244,11 @@ func autoFixIndex() {
 		return
 	}
 
+	if isCheckoutRepo {
+		logging.LogInfof("skip check index caused by checkout repo")
+		return
+	}
+
 	if util.IsMutexLocked(&autoFixLock) {
 		return
 	}
@@ -1286,6 +1291,12 @@ func autoFixIndex() {
 				break
 			}
 
+			id := path.Base(p)
+			id = strings.TrimSuffix(id, ".sy")
+			if !ast.IsNodeIDPattern(id) {
+				continue
+			}
+
 			reindexTreeByPath(box.ID, p, i, size)
 		}
 	}