mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-30 05:18:49 +01:00
🎨 使用第三方同步盘时弹出提示并退出内核 https://github.com/siyuan-note/siyuan/issues/7683
This commit is contained in:
parent
d7473b7a6d
commit
5f6d1eac9a
17 changed files with 69 additions and 171 deletions
|
|
@ -1000,7 +1000,7 @@
|
|||
"73": "Importing, please wait...",
|
||||
"74": "The kernel has not been fully booted [%d%%], please try again later",
|
||||
"75": "Attempt to access file failed",
|
||||
"76": "The data file has been locked by another program.",
|
||||
"76": "TODO",
|
||||
"77": "Invalid dir path [%s]",
|
||||
"78": "The old and new paths are repeated",
|
||||
"79": "Only supports importing Markdown document",
|
||||
|
|
|
|||
|
|
@ -1000,7 +1000,7 @@
|
|||
"73": "Importando, por favor espere...",
|
||||
"74": "El kernel no ha sido arrancado completamente [%d%%], por favor, inténtelo de nuevo más tarde",
|
||||
"75": "Error al intentar acceder al archivo",
|
||||
"76": "El archivo de datos ha sido bloqueado por otro programa.",
|
||||
"76": "TODO",
|
||||
"77": "Ruta inválida [%s]",
|
||||
"78": "Los viejos y nuevos caminos se repiten",
|
||||
"79": "Sólo admite la importación de documentos Markdown",
|
||||
|
|
|
|||
|
|
@ -1000,7 +1000,7 @@
|
|||
"73": "En cours d'importation, veuillez patienter...",
|
||||
"74": "Le kernel n'a pas été complètement démarré [%d%%], veuillez réessayer plus tard.",
|
||||
"75": "La tentative d'accès au fichier a échoué",
|
||||
"76": "Le fichier de données a été verrouillé par un autre programme.",
|
||||
"76": "TODO",
|
||||
"77": "Chemin d'accès invalide [%s]",
|
||||
"78": "Les anciens et les nouveaux chemins sont répétés",
|
||||
"79": "Prise en charge de l'importation de documents Markdown uniquement",
|
||||
|
|
|
|||
|
|
@ -1000,7 +1000,7 @@
|
|||
"73": "正在導入,請稍等...",
|
||||
"74": "kernel尚未完全啟動 [%d%%],請稍後再試",
|
||||
"75": "嘗試訪問資料檔失敗",
|
||||
"76": "資料檔案已被其他程式鎖定。",
|
||||
"76": "TODO",
|
||||
"77": "不可用的目錄路徑 [%s]",
|
||||
"78": "新老路徑重複",
|
||||
"79": "僅支援導入 Markdown 文檔",
|
||||
|
|
|
|||
|
|
@ -1000,7 +1000,7 @@
|
|||
"73": "正在导入,请稍等...",
|
||||
"74": "内核尚未完全启动 [%d%%],请稍后再试",
|
||||
"75": "尝试访问文件失败",
|
||||
"76": "数据文件已被其他程序锁定。",
|
||||
"76": "TODO",
|
||||
"77": "不可用的目录路径 [%s]",
|
||||
"78": "新老路径重复",
|
||||
"79": "仅支持导入 Markdown 文档",
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import (
|
|||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/html"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/model"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
|
|
@ -195,11 +194,12 @@ func checkBlockExist(c *gin.Context) {
|
|||
|
||||
id := arg["id"].(string)
|
||||
b, err := model.GetBlock(id, nil)
|
||||
if errors.Is(err, filelock.ErrUnableAccessFile) {
|
||||
ret.Code = 2
|
||||
ret.Data = id
|
||||
return
|
||||
}
|
||||
// TODO 文件被锁的情况已经在 filelock 中做了退出进程处理,不会走到应用层,所以 code 为 2 的情况应该移除
|
||||
//if errors.Is(err, filelock.ErrUnableAccessFile) {
|
||||
// ret.Code = 2
|
||||
// ret.Data = id
|
||||
// return
|
||||
//}
|
||||
if errors.Is(err, model.ErrIndexing) {
|
||||
ret.Code = 0
|
||||
ret.Data = false
|
||||
|
|
@ -405,11 +405,11 @@ func getBlockInfo(c *gin.Context) {
|
|||
id := arg["id"].(string)
|
||||
|
||||
tree, err := model.LoadTreeByID(id)
|
||||
if errors.Is(err, filelock.ErrUnableAccessFile) {
|
||||
ret.Code = 2
|
||||
ret.Data = id
|
||||
return
|
||||
}
|
||||
//if errors.Is(err, filelock.ErrUnableAccessFile) {
|
||||
// ret.Code = 2
|
||||
// ret.Data = id
|
||||
// return
|
||||
//}
|
||||
if errors.Is(err, model.ErrIndexing) {
|
||||
ret.Code = 3
|
||||
ret.Msg = model.Conf.Language(56)
|
||||
|
|
@ -438,11 +438,11 @@ func getBlockInfo(c *gin.Context) {
|
|||
}
|
||||
|
||||
root, err := model.GetBlock(block.RootID, tree)
|
||||
if errors.Is(err, filelock.ErrUnableAccessFile) {
|
||||
ret.Code = 2
|
||||
ret.Data = id
|
||||
return
|
||||
}
|
||||
//if errors.Is(err, filelock.ErrUnableAccessFile) {
|
||||
// ret.Code = 2
|
||||
// ret.Data = id
|
||||
// return
|
||||
//}
|
||||
if errors.Is(err, model.ErrIndexing) {
|
||||
ret.Code = 3
|
||||
ret.Data = model.Conf.Language(56)
|
||||
|
|
|
|||
|
|
@ -61,13 +61,7 @@ func appendBlock(c *gin.Context) {
|
|||
},
|
||||
}
|
||||
|
||||
err := model.PerformTransactions(&transactions)
|
||||
if nil != err {
|
||||
ret.Code = 1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
model.PerformTransactions(&transactions)
|
||||
model.WaitForWritingFiles()
|
||||
|
||||
ret.Data = transactions
|
||||
|
|
@ -106,13 +100,7 @@ func prependBlock(c *gin.Context) {
|
|||
},
|
||||
}
|
||||
|
||||
err := model.PerformTransactions(&transactions)
|
||||
if nil != err {
|
||||
ret.Code = 1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
model.PerformTransactions(&transactions)
|
||||
model.WaitForWritingFiles()
|
||||
|
||||
ret.Data = transactions
|
||||
|
|
@ -169,13 +157,7 @@ func insertBlock(c *gin.Context) {
|
|||
},
|
||||
}
|
||||
|
||||
err := model.PerformTransactions(&transactions)
|
||||
if nil != err {
|
||||
ret.Code = 1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
model.PerformTransactions(&transactions)
|
||||
model.WaitForWritingFiles()
|
||||
|
||||
ret.Data = transactions
|
||||
|
|
@ -260,13 +242,7 @@ func updateBlock(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
err = model.PerformTransactions(&transactions)
|
||||
if nil != err {
|
||||
ret.Code = 1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
model.PerformTransactions(&transactions)
|
||||
model.WaitForWritingFiles()
|
||||
|
||||
ret.Data = transactions
|
||||
|
|
@ -298,12 +274,7 @@ func deleteBlock(c *gin.Context) {
|
|||
},
|
||||
}
|
||||
|
||||
err := model.PerformTransactions(&transactions)
|
||||
if nil != err {
|
||||
ret.Code = 1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
model.PerformTransactions(&transactions)
|
||||
|
||||
ret.Data = transactions
|
||||
broadcastTransactions(transactions)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path"
|
||||
|
|
@ -27,7 +26,6 @@ import (
|
|||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||
"github.com/siyuan-note/siyuan/kernel/model"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
|
|
@ -691,11 +689,11 @@ func getDoc(c *gin.Context) {
|
|||
}
|
||||
|
||||
blockCount, content, parentID, parent2ID, rootID, typ, eof, scroll, boxID, docPath, isBacklinkExpand, err := model.GetDoc(startID, endID, id, index, keyword, mode, size, isBacklink)
|
||||
if errors.Is(err, filelock.ErrUnableAccessFile) {
|
||||
ret.Code = 2
|
||||
ret.Data = id
|
||||
return
|
||||
}
|
||||
//if errors.Is(err, filelock.ErrUnableAccessFile) {
|
||||
// ret.Code = 2
|
||||
// ret.Data = id
|
||||
// return
|
||||
//}
|
||||
if model.ErrBlockNotFound == err {
|
||||
ret.Code = 3
|
||||
return
|
||||
|
|
|
|||
|
|
@ -17,14 +17,12 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/siyuan/kernel/model"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
|
@ -61,10 +59,7 @@ func performTransactions(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if err = model.PerformTransactions(&transactions); errors.Is(err, filelock.ErrUnableAccessFile) {
|
||||
ret.Code = 1
|
||||
return
|
||||
}
|
||||
model.PerformTransactions(&transactions)
|
||||
|
||||
ret.Data = transactions
|
||||
|
||||
|
|
|
|||
|
|
@ -41,10 +41,6 @@ func LoadTree(boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, err erro
|
|||
data, err := filelock.ReadFile(filePath)
|
||||
if nil != err {
|
||||
logging.LogErrorf("load tree [%s] failed: %s", p, err)
|
||||
if errors.Is(err, filelock.ErrUnableAccessFile) {
|
||||
os.Exit(logging.ExitCodeFileSysInconsistent)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -96,10 +92,6 @@ func LoadTreeByData(data []byte, boxID, p string, luteEngine *lute.Lute) (ret *p
|
|||
}
|
||||
} else {
|
||||
logging.LogWarnf("read parent tree data [%s] failed: %s", parentAbsPath, readErr)
|
||||
if errors.Is(readErr, filelock.ErrUnableAccessFile) {
|
||||
os.Exit(logging.ExitCodeFileSysInconsistent)
|
||||
return
|
||||
}
|
||||
}
|
||||
hPathBuilder.WriteString("Untitled/")
|
||||
continue
|
||||
|
|
@ -129,10 +121,6 @@ func WriteTreeWithoutChangeTime(tree *parse.Tree) (err error) {
|
|||
}
|
||||
|
||||
if err = filelock.WriteFileWithoutChangeTime(filePath, data); nil != err {
|
||||
if errors.Is(err, filelock.ErrUnableAccessFile) {
|
||||
return
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("write data [%s] failed: %s", filePath, err)
|
||||
logging.LogErrorf(msg)
|
||||
return errors.New(msg)
|
||||
|
|
@ -149,10 +137,6 @@ func WriteTree(tree *parse.Tree) (err error) {
|
|||
}
|
||||
|
||||
if err = filelock.WriteFile(filePath, data); nil != err {
|
||||
if errors.Is(err, filelock.ErrUnableAccessFile) {
|
||||
return
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("write data [%s] failed: %s", filePath, err)
|
||||
logging.LogErrorf(msg)
|
||||
return errors.New(msg)
|
||||
|
|
|
|||
|
|
@ -45,9 +45,9 @@ require (
|
|||
github.com/siyuan-note/dejavu v0.0.0-20230315034343-e9513a7e1999
|
||||
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75
|
||||
github.com/siyuan-note/eventbus v0.0.0-20230216103454-41885eac6c2b
|
||||
github.com/siyuan-note/filelock v0.0.0-20230318101209-f0e353df8b5b
|
||||
github.com/siyuan-note/filelock v0.0.0-20230318155428-4b54cef95279
|
||||
github.com/siyuan-note/httpclient v0.0.0-20230309131049-f703795de6bc
|
||||
github.com/siyuan-note/logging v0.0.0-20230318100514-8ece27db458d
|
||||
github.com/siyuan-note/logging v0.0.0-20230318155021-66a29c2075ee
|
||||
github.com/siyuan-note/riff v0.0.0-20230224144841-cfbe0748ddb7
|
||||
github.com/steambap/captcha v1.4.1
|
||||
github.com/studio-b12/gowebdav v0.0.0-20230203202212-3282f94193f2
|
||||
|
|
@ -126,7 +126,6 @@ require (
|
|||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
||||
go.uber.org/multierr v1.10.0 // indirect
|
||||
golang.org/x/arch v0.3.0 // indirect
|
||||
golang.org/x/crypto v0.7.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20230314191032-db074128a8ec // indirect
|
||||
|
|
|
|||
|
|
@ -283,12 +283,12 @@ github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29
|
|||
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw=
|
||||
github.com/siyuan-note/eventbus v0.0.0-20230216103454-41885eac6c2b h1:828lTUW2C0uNiolODqoACu7J8sDUzswD4Xo04mUombg=
|
||||
github.com/siyuan-note/eventbus v0.0.0-20230216103454-41885eac6c2b/go.mod h1:Sqo4FYX5lAXu7gWkbEdJF0e6P57tNNVV4WDKYDctokI=
|
||||
github.com/siyuan-note/filelock v0.0.0-20230318101209-f0e353df8b5b h1:NtC1PhGKtOvjQNf95UUW3K5OW/0OIu3ny8sLq9YYqOQ=
|
||||
github.com/siyuan-note/filelock v0.0.0-20230318101209-f0e353df8b5b/go.mod h1:kL4KLZ3/SJxQFQ/lUxkbOyQiqVh/MJyo1CGy6sAUqM8=
|
||||
github.com/siyuan-note/filelock v0.0.0-20230318155428-4b54cef95279 h1:sEP5/DN/Gd3AE51wxujJQyH2BYWhgQ4PMCJVG/92VJs=
|
||||
github.com/siyuan-note/filelock v0.0.0-20230318155428-4b54cef95279/go.mod h1:IBWcCZc4ihicGp4FJgytb8uE2/NN9XNvyv8Pn3lmmo8=
|
||||
github.com/siyuan-note/httpclient v0.0.0-20230309131049-f703795de6bc h1:MX2cPWpn7Hfd3FmpwLjGdPIjF84AFUS9f/mcPJc/4w4=
|
||||
github.com/siyuan-note/httpclient v0.0.0-20230309131049-f703795de6bc/go.mod h1:WDO42mUVRnkk8M4AhZ4oakZ5jnghulP0c8NFCrrFWG4=
|
||||
github.com/siyuan-note/logging v0.0.0-20230318100514-8ece27db458d h1:K7y9mEvoQ2PZkM0f+bHvnyDi/gnKfY5OJjYUe2GFnpc=
|
||||
github.com/siyuan-note/logging v0.0.0-20230318100514-8ece27db458d/go.mod h1:6mRFtAAvYPn3cDzqvyv+t8BVPGqpONDMMb5ywOhY1D4=
|
||||
github.com/siyuan-note/logging v0.0.0-20230318155021-66a29c2075ee h1:KwU0r4UjabPFjVsXhYmNfm1QRdcj1ps5o1XxsTIJ924=
|
||||
github.com/siyuan-note/logging v0.0.0-20230318155021-66a29c2075ee/go.mod h1:6mRFtAAvYPn3cDzqvyv+t8BVPGqpONDMMb5ywOhY1D4=
|
||||
github.com/siyuan-note/riff v0.0.0-20230224144841-cfbe0748ddb7 h1:Kr8hhMhr6v+U24TMDCP5WdP4dWrXm5maar+TycTZs9I=
|
||||
github.com/siyuan-note/riff v0.0.0-20230224144841-cfbe0748ddb7/go.mod h1:XJtLlKCr8cZE+lzykM4edHHih92M9M50UNw/nDLYRN8=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||
|
|
@ -338,8 +338,6 @@ github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
|
|||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
|
||||
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
|
||||
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||
golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
|
||||
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -112,84 +112,84 @@ func InitDatabase(forceRebuild bool) (err error) {
|
|||
func initDBTables() {
|
||||
_, err := db.Exec("DROP TABLE IF EXISTS stat")
|
||||
if nil != err {
|
||||
logging.LogFatalf("drop table [stat] failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "drop table [stat] failed: %s", err)
|
||||
}
|
||||
_, err = db.Exec("CREATE TABLE stat (key, value)")
|
||||
if nil != err {
|
||||
logging.LogFatalf("create table [stat] failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [stat] failed: %s", err)
|
||||
}
|
||||
setDatabaseVer()
|
||||
|
||||
_, err = db.Exec("DROP TABLE IF EXISTS blocks")
|
||||
if nil != err {
|
||||
logging.LogFatalf("drop table [blocks] failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "drop table [blocks] failed: %s", err)
|
||||
}
|
||||
_, err = db.Exec("CREATE TABLE blocks (id, parent_id, root_id, hash, box, path, hpath, name, alias, memo, tag, content, fcontent, markdown, length, type, subtype, ial, sort, created, updated)")
|
||||
if nil != err {
|
||||
logging.LogFatalf("create table [blocks] failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [blocks] failed: %s", err)
|
||||
}
|
||||
|
||||
_, err = db.Exec("DROP TABLE IF EXISTS blocks_fts")
|
||||
if nil != err {
|
||||
logging.LogFatalf("drop table [blocks_fts] failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "drop table [blocks_fts] failed: %s", err)
|
||||
}
|
||||
_, err = db.Exec("CREATE VIRTUAL TABLE blocks_fts USING fts5(id UNINDEXED, parent_id UNINDEXED, root_id UNINDEXED, hash UNINDEXED, box UNINDEXED, path UNINDEXED, hpath, name, alias, memo, tag, content, fcontent, markdown UNINDEXED, length UNINDEXED, type UNINDEXED, subtype UNINDEXED, ial, sort UNINDEXED, created UNINDEXED, updated UNINDEXED, tokenize=\"siyuan\")")
|
||||
if nil != err {
|
||||
logging.LogFatalf("create table [blocks_fts] failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [blocks_fts] failed: %s", err)
|
||||
}
|
||||
|
||||
_, err = db.Exec("DROP TABLE IF EXISTS blocks_fts_case_insensitive")
|
||||
if nil != err {
|
||||
logging.LogFatalf("drop table [blocks_fts_case_insensitive] failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "drop table [blocks_fts_case_insensitive] failed: %s", err)
|
||||
}
|
||||
_, err = db.Exec("CREATE VIRTUAL TABLE blocks_fts_case_insensitive USING fts5(id UNINDEXED, parent_id UNINDEXED, root_id UNINDEXED, hash UNINDEXED, box UNINDEXED, path UNINDEXED, hpath, name, alias, memo, tag, content, fcontent, markdown UNINDEXED, length UNINDEXED, type UNINDEXED, subtype UNINDEXED, ial, sort UNINDEXED, created UNINDEXED, updated UNINDEXED, tokenize=\"siyuan case_insensitive\")")
|
||||
if nil != err {
|
||||
logging.LogFatalf("create table [blocks_fts_case_insensitive] failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [blocks_fts_case_insensitive] failed: %s", err)
|
||||
}
|
||||
|
||||
_, err = db.Exec("DROP TABLE IF EXISTS spans")
|
||||
if nil != err {
|
||||
logging.LogFatalf("drop table [spans] failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "drop table [spans] failed: %s", err)
|
||||
}
|
||||
_, err = db.Exec("CREATE TABLE spans (id, block_id, root_id, box, path, content, markdown, type, ial)")
|
||||
if nil != err {
|
||||
logging.LogFatalf("create table [spans] failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [spans] failed: %s", err)
|
||||
}
|
||||
|
||||
_, err = db.Exec("DROP TABLE IF EXISTS assets")
|
||||
if nil != err {
|
||||
logging.LogFatalf("drop table [assets] failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "drop table [assets] failed: %s", err)
|
||||
}
|
||||
_, err = db.Exec("CREATE TABLE assets (id, block_id, root_id, box, docpath, path, name, title, hash)")
|
||||
if nil != err {
|
||||
logging.LogFatalf("create table [assets] failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [assets] failed: %s", err)
|
||||
}
|
||||
|
||||
_, err = db.Exec("DROP TABLE IF EXISTS attributes")
|
||||
if nil != err {
|
||||
logging.LogFatalf("drop table [attributes] failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "drop table [attributes] failed: %s", err)
|
||||
}
|
||||
_, err = db.Exec("CREATE TABLE attributes (id, name, value, type, block_id, root_id, box, path)")
|
||||
if nil != err {
|
||||
logging.LogFatalf("create table [attributes] failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [attributes] failed: %s", err)
|
||||
}
|
||||
|
||||
_, err = db.Exec("DROP TABLE IF EXISTS refs")
|
||||
if nil != err {
|
||||
logging.LogFatalf("drop table [refs] failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "drop table [refs] failed: %s", err)
|
||||
}
|
||||
_, err = db.Exec("CREATE TABLE refs (id, def_block_id, def_block_parent_id, def_block_root_id, def_block_path, block_id, root_id, box, path, content, markdown, type)")
|
||||
if nil != err {
|
||||
logging.LogFatalf("create table [refs] failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [refs] failed: %s", err)
|
||||
}
|
||||
|
||||
_, err = db.Exec("DROP TABLE IF EXISTS file_annotation_refs")
|
||||
if nil != err {
|
||||
logging.LogFatalf("drop table [refs] failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "drop table [refs] failed: %s", err)
|
||||
}
|
||||
_, err = db.Exec("CREATE TABLE file_annotation_refs (id, file_path, annotation_id, block_id, root_id, box, path, content, type)")
|
||||
if nil != err {
|
||||
logging.LogFatalf("create table [refs] failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [refs] failed: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -228,7 +228,7 @@ func initHistoryDBConnection() {
|
|||
var err error
|
||||
historyDB, err = sql.Open("sqlite3_extended", dsn)
|
||||
if nil != err {
|
||||
logging.LogFatalf("create database failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create database failed: %s", err)
|
||||
}
|
||||
historyDB.SetMaxIdleConns(3)
|
||||
historyDB.SetMaxOpenConns(3)
|
||||
|
|
@ -239,7 +239,7 @@ func initHistoryDBTables() {
|
|||
historyDB.Exec("DROP TABLE histories_fts_case_insensitive")
|
||||
_, err := historyDB.Exec("CREATE VIRTUAL TABLE histories_fts_case_insensitive USING fts5(type UNINDEXED, op UNINDEXED, title, content, path UNINDEXED, created UNINDEXED, tokenize=\"siyuan case_insensitive\")")
|
||||
if nil != err {
|
||||
logging.LogFatalf("create table [histories_fts_case_insensitive] failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create table [histories_fts_case_insensitive] failed: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -260,7 +260,7 @@ func initDBConnection() {
|
|||
var err error
|
||||
db, err = sql.Open("sqlite3_extended", dsn)
|
||||
if nil != err {
|
||||
logging.LogFatalf("create database failed: %s", err)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "create database failed: %s", err)
|
||||
}
|
||||
db.SetMaxIdleConns(20)
|
||||
db.SetMaxOpenConns(20)
|
||||
|
|
@ -1206,7 +1206,7 @@ func execStmtTx(tx *sql.Tx, stmt string, args ...interface{}) (err error) {
|
|||
tx.Rollback()
|
||||
closeDatabase()
|
||||
removeDatabaseFile()
|
||||
logging.LogFatalf("database disk image [%s] is malformed, please restart SiYuan kernel to rebuild it", util.DBPath)
|
||||
logging.LogFatalf(logging.ExitCodeReadOnlyDatabase, "database disk image [%s] is malformed, please restart SiYuan kernel to rebuild it", util.DBPath)
|
||||
}
|
||||
logging.LogErrorf("exec database stmt [%s] failed: %s\n %s", stmt, err, logging.ShortStack())
|
||||
return
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ func FormatNode(node *ast.Node, luteEngine *lute.Lute) string {
|
|||
markdown, err := lute.FormatNodeSync(node, luteEngine.ParseOptions, luteEngine.RenderOptions)
|
||||
if nil != err {
|
||||
root := TreeRoot(node)
|
||||
logging.LogFatalf("format node [%s] in tree [%s] failed: %s", node.ID, root.ID, err)
|
||||
logging.LogFatalf(logging.ExitCodeFatal, "format node [%s] in tree [%s] failed: %s", node.ID, root.ID, err)
|
||||
}
|
||||
return markdown
|
||||
}
|
||||
|
|
@ -127,7 +127,7 @@ func ExportNodeStdMd(node *ast.Node, luteEngine *lute.Lute) string {
|
|||
markdown, err := lute.ProtyleExportMdNodeSync(node, luteEngine.ParseOptions, luteEngine.RenderOptions)
|
||||
if nil != err {
|
||||
root := TreeRoot(node)
|
||||
logging.LogFatalf("export markdown for node [%s] in tree [%s] failed: %s", node.ID, root.ID, err)
|
||||
logging.LogFatalf(logging.ExitCodeFatal, "export markdown for node [%s] in tree [%s] failed: %s", node.ID, root.ID, err)
|
||||
}
|
||||
return markdown
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue