🎨 使用第三方同步盘时弹出提示并退出内核 https://github.com/siyuan-note/siyuan/issues/7683

This commit is contained in:
Liang Ding 2023-03-19 00:12:28 +08:00
parent d7473b7a6d
commit 5f6d1eac9a
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
17 changed files with 69 additions and 171 deletions

View file

@ -18,7 +18,6 @@ package model
import (
"bytes"
"errors"
"fmt"
"path/filepath"
"strings"
@ -107,11 +106,8 @@ func flushTx() {
case TxErrCodeBlockNotFound:
util.PushTxErr("Transaction failed", txErr.code, nil)
return
case TxErrCodeUnableAccessFile:
util.PushTxErr(Conf.Language(76), txErr.code, txErr.id)
return
default:
logging.LogFatalf("transaction failed: %s", txErr.msg)
logging.LogFatalf(logging.ExitCodeFatal, "transaction failed: %s", txErr.msg)
}
}
elapsed := time.Now().Sub(start).Milliseconds()
@ -150,7 +146,7 @@ func mergeTx() (ret *Transaction) {
return
}
func PerformTransactions(transactions *[]*Transaction) (err error) {
func PerformTransactions(transactions *[]*Transaction) {
txQueueLock.Lock()
txQueue = append(txQueue, *transactions...)
txQueueLock.Unlock()
@ -158,10 +154,9 @@ func PerformTransactions(transactions *[]*Transaction) (err error) {
}
const (
TxErrCodeBlockNotFound = 0
TxErrCodeUnableAccessFile = 1
TxErrCodeWriteTree = 2
TxErrWriteAttributeView = 3
TxErrCodeBlockNotFound = 0
TxErrCodeWriteTree = 2
TxErrWriteAttributeView = 3
)
type TxErr struct {
@ -231,10 +226,6 @@ func performTx(tx *Transaction) (ret *TxErr) {
}
if cr := tx.commit(); nil != cr {
if errors.Is(cr, filelock.ErrUnableAccessFile) {
return &TxErr{code: TxErrCodeUnableAccessFile, msg: cr.Error()}
}
logging.LogErrorf("commit tx failed: %s", cr)
return &TxErr{msg: cr.Error()}
}
@ -420,9 +411,6 @@ func (tx *Transaction) doPrependInsert(operation *Operation) (ret *TxErr) {
return &TxErr{code: TxErrCodeBlockNotFound, id: operation.ParentID}
}
tree, err := tx.loadTree(block.ID)
if errors.Is(err, filelock.ErrUnableAccessFile) {
return &TxErr{code: TxErrCodeUnableAccessFile, msg: err.Error(), id: block.ID}
}
if nil != err {
msg := fmt.Sprintf("load tree [%s] failed: %s", block.ID, err)
logging.LogErrorf(msg)
@ -507,9 +495,6 @@ func (tx *Transaction) doAppendInsert(operation *Operation) (ret *TxErr) {
return &TxErr{code: TxErrCodeBlockNotFound, id: operation.ParentID}
}
tree, err := tx.loadTree(block.ID)
if errors.Is(err, filelock.ErrUnableAccessFile) {
return &TxErr{code: TxErrCodeUnableAccessFile, msg: err.Error(), id: block.ID}
}
if nil != err {
msg := fmt.Sprintf("load tree [%s] failed: %s", block.ID, err)
logging.LogErrorf(msg)
@ -664,9 +649,6 @@ func (tx *Transaction) doDelete(operation *Operation) (ret *TxErr) {
var err error
id := operation.ID
tree, err := tx.loadTree(id)
if errors.Is(err, filelock.ErrUnableAccessFile) {
return &TxErr{code: TxErrCodeUnableAccessFile, msg: err.Error(), id: id}
}
if ErrBlockNotFound == err {
return nil // move 以后这里会空,算作正常情况
}
@ -719,9 +701,6 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
}
tree, err := tx.loadTree(block.ID)
if errors.Is(err, filelock.ErrUnableAccessFile) {
return &TxErr{code: TxErrCodeUnableAccessFile, msg: err.Error(), id: block.ID}
}
if nil != err {
msg := fmt.Sprintf("load tree [%s] failed: %s", block.ID, err)
logging.LogErrorf(msg)
@ -864,9 +843,6 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
id := operation.ID
tree, err := tx.loadTree(id)
if errors.Is(err, filelock.ErrUnableAccessFile) {
return &TxErr{code: TxErrCodeUnableAccessFile, msg: err.Error(), id: id}
}
if nil != err {
logging.LogErrorf("load tree [%s] failed: %s", id, err)
return &TxErr{code: TxErrCodeBlockNotFound, id: id}