mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-24 02:20:13 +01:00
🎨 使用第三方同步盘时弹出提示并退出内核 https://github.com/siyuan-note/siyuan/issues/7683
This commit is contained in:
parent
f2f60cf9fe
commit
5971076749
3 changed files with 39 additions and 16 deletions
|
|
@ -41,6 +41,10 @@ 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(util.ExitCodeFileSysInconsistent)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -92,6 +96,10 @@ 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(util.ExitCodeFileSysInconsistent)
|
||||
return
|
||||
}
|
||||
}
|
||||
hPathBuilder.WriteString("Untitled/")
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ func FlushQueue() {
|
|||
context["total"] = groupOpsTotal[op.action]
|
||||
if err = execOp(op, tx, context); nil != err {
|
||||
tx.Rollback()
|
||||
logging.LogErrorf("queue operation failed: %s", err)
|
||||
logging.LogErrorf("queue operation [%s] failed: %s", op.action, err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
|
|
@ -137,7 +138,12 @@ func CheckFileSysStatus() {
|
|||
|
||||
reportFileSysFatalError := func(err error) {
|
||||
stack := debug.Stack()
|
||||
logging.LogErrorf("check file system status failed: %s, %s", err, stack)
|
||||
output := string(stack)
|
||||
if 5 < strings.Count(output, "\n") {
|
||||
lines := strings.Split(output, "\n")
|
||||
output = strings.Join(lines[5:], "\n")
|
||||
}
|
||||
logging.LogErrorf("check file system status failed: %s, %s", err, output)
|
||||
os.Exit(ExitCodeFileSysInconsistent)
|
||||
}
|
||||
|
||||
|
|
@ -179,7 +185,15 @@ func CheckFileSysStatus() {
|
|||
time.Sleep(time.Second)
|
||||
|
||||
for j := 0; j < 32; j++ {
|
||||
f, err := os.Open(tmp)
|
||||
renamed := tmp + "_renamed"
|
||||
if err = os.Rename(tmp, renamed); nil != err {
|
||||
reportFileSysFatalError(err)
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
f, err := os.Open(renamed)
|
||||
if nil != err {
|
||||
reportFileSysFatalError(err)
|
||||
break
|
||||
|
|
@ -190,15 +204,7 @@ func CheckFileSysStatus() {
|
|||
break
|
||||
}
|
||||
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
if err = os.Rename(tmp, tmp+"_renamed"); nil != err {
|
||||
reportFileSysFatalError(err)
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
if err = os.Rename(tmp+"_renamed", tmp); nil != err {
|
||||
if err = os.Rename(renamed, tmp); nil != err {
|
||||
reportFileSysFatalError(err)
|
||||
break
|
||||
}
|
||||
|
|
@ -209,14 +215,23 @@ func CheckFileSysStatus() {
|
|||
break
|
||||
}
|
||||
|
||||
count := 0
|
||||
checkFilenames := bytes.Buffer{}
|
||||
for _, entry := range entries {
|
||||
if !entry.IsDir() && strings.Contains(entry.Name(), "check_") {
|
||||
count++
|
||||
checkFilenames.WriteString(entry.Name())
|
||||
checkFilenames.WriteString("\n")
|
||||
}
|
||||
}
|
||||
if 1 < count {
|
||||
reportFileSysFatalError(fmt.Errorf("dir [%s] has more than 1 file", dir))
|
||||
lines := strings.Split(strings.TrimSpace(checkFilenames.String()), "\n")
|
||||
if 1 < len(lines) {
|
||||
buf := bytes.Buffer{}
|
||||
for _, line := range lines {
|
||||
buf.WriteString(" ")
|
||||
buf.WriteString(line)
|
||||
buf.WriteString("\n")
|
||||
}
|
||||
output := buf.String()
|
||||
reportFileSysFatalError(fmt.Errorf("dir [%s] has more than 1 file:\n%s", dir, output))
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue