🎨 使用第三方同步盘时弹出提示并退出内核 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

@ -896,10 +896,7 @@ func DuplicateDoc(tree *parse.Tree) {
func createTreeTx(tree *parse.Tree) {
transaction := &Transaction{DoOperations: []*Operation{{Action: "create", Data: tree}}}
err := PerformTransactions(&[]*Transaction{transaction})
if nil != err {
logging.LogFatalf("transaction failed: %s", err)
}
PerformTransactions(&[]*Transaction{transaction})
}
func CreateDocByMd(boxID, p, title, md string, sorts []string) (tree *parse.Tree, err error) {
@ -1450,11 +1447,7 @@ func createDoc(boxID, p, title, dom string) (tree *parse.Tree, err error) {
}
transaction := &Transaction{DoOperations: []*Operation{{Action: "create", Data: tree}}}
err = PerformTransactions(&[]*Transaction{transaction})
if nil != err {
logging.LogFatalf("transaction failed: %s", err)
return
}
PerformTransactions(&[]*Transaction{transaction})
WaitForWritingFiles()
return
}

View file

@ -259,10 +259,6 @@ func setCriteria(criteria []*Criterion) (err error) {
err = filelock.WriteFile(lsPath, data)
if nil != err {
logging.LogErrorf("write storage [criteria] failed: %s", err)
if errors.Is(err, filelock.ErrUnableAccessFile) {
os.Exit(logging.ExitCodeFileSysInconsistent)
return
}
return
}
return
@ -278,10 +274,6 @@ func getCriteria() (ret []*Criterion, err error) {
data, err := filelock.ReadFile(dataPath)
if nil != err {
logging.LogErrorf("read storage [criteria] failed: %s", err)
if errors.Is(err, filelock.ErrUnableAccessFile) {
os.Exit(logging.ExitCodeFileSysInconsistent)
return
}
return
}
@ -353,10 +345,6 @@ func setLocalStorage(val interface{}) (err error) {
err = filelock.WriteFile(lsPath, data)
if nil != err {
logging.LogErrorf("write storage [local] failed: %s", err)
if errors.Is(err, filelock.ErrUnableAccessFile) {
os.Exit(logging.ExitCodeFileSysInconsistent)
return
}
return
}
return
@ -372,10 +360,6 @@ func getLocalStorage() (ret map[string]interface{}, err error) {
data, err := filelock.ReadFile(lsPath)
if nil != err {
logging.LogErrorf("read storage [local] failed: %s", err)
if errors.Is(err, filelock.ErrUnableAccessFile) {
os.Exit(logging.ExitCodeFileSysInconsistent)
return
}
return
}

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}