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

This commit is contained in:
Liang Ding 2023-03-17 21:43:38 +08:00
parent 2af8b67cbd
commit f9520e3a08
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
4 changed files with 59 additions and 43 deletions

View file

@ -35,13 +35,17 @@ import (
func InitAppearance() {
util.SetBootDetails("Initializing appearance...")
if err := os.Mkdir(util.AppearancePath, 0755); nil != err && !os.IsExist(err) {
logging.LogFatalf("create appearance folder [%s] failed: %s", util.AppearancePath, err)
logging.LogErrorf("create appearance folder [%s] failed: %s", util.AppearancePath, err)
util.ReportFileSysFatalError(err)
return
}
unloadThemes()
from := filepath.Join(util.WorkingDir, "appearance")
if err := gulu.File.Copy(from, util.AppearancePath); nil != err {
logging.LogFatalf("copy appearance resources from [%s] to [%s] failed: %s", from, util.AppearancePath, err)
logging.LogErrorf("copy appearance resources from [%s] to [%s] failed: %s", from, util.AppearancePath, err)
util.ReportFileSysFatalError(err)
return
}
loadThemes()
@ -95,7 +99,9 @@ func unloadThemes() {
func loadThemes() {
themeDirs, err := os.ReadDir(util.ThemesPath)
if nil != err {
logging.LogFatalf("read appearance themes folder failed: %s", err)
logging.LogErrorf("read appearance themes folder failed: %s", err)
util.ReportFileSysFatalError(err)
return
}
Conf.Appearance.DarkThemes = nil
@ -204,7 +210,9 @@ func widgetJSON(widgetName string) (ret map[string]interface{}, err error) {
func loadIcons() {
iconDirs, err := os.ReadDir(util.IconsPath)
if nil != err {
logging.LogFatalf("read appearance icons folder failed: %s", err)
logging.LogErrorf("read appearance icons folder failed: %s", err)
util.ReportFileSysFatalError(err)
return
}
Conf.Appearance.Icons = nil

View file

@ -343,13 +343,17 @@ func initLang() {
p := filepath.Join(util.WorkingDir, "appearance", "langs")
dir, err := os.Open(p)
if nil != err {
logging.LogFatalf("open language configuration folder [%s] failed: %s", p, err)
logging.LogErrorf("open language configuration folder [%s] failed: %s", p, err)
util.ReportFileSysFatalError(err)
return
}
defer dir.Close()
langNames, err := dir.Readdirnames(-1)
if nil != err {
logging.LogFatalf("list language configuration folder [%s] failed: %s", p, err)
logging.LogErrorf("list language configuration folder [%s] failed: %s", p, err)
util.ReportFileSysFatalError(err)
return
}
for _, langName := range langNames {
@ -510,7 +514,9 @@ func (conf *AppConf) Save() {
func (conf *AppConf) save0(data []byte) {
confPath := filepath.Join(util.ConfDir, "conf.json")
if err := filelock.WriteFile(confPath, data); nil != err {
logging.LogFatalf("write conf [%s] failed: %s", confPath, err)
logging.LogErrorf("write conf [%s] failed: %s", confPath, err)
util.ReportFileSysFatalError(err)
return
}
}

View file

@ -217,12 +217,14 @@ func serveAppearance(ginServer *gin.Engine) {
enUSFilePath := filepath.Join(appearancePath, "langs", "en_US.json")
enUSData, err := os.ReadFile(enUSFilePath)
if nil != err {
logging.LogFatalf("read en_US.json [%s] failed: %s", enUSFilePath, err)
logging.LogErrorf("read en_US.json [%s] failed: %s", enUSFilePath, err)
util.ReportFileSysFatalError(err)
return
}
enUSMap := map[string]interface{}{}
if err = gulu.JSON.UnmarshalJSON(enUSData, &enUSMap); nil != err {
logging.LogFatalf("unmarshal en_US.json [%s] failed: %s", enUSFilePath, err)
logging.LogErrorf("unmarshal en_US.json [%s] failed: %s", enUSFilePath, err)
util.ReportFileSysFatalError(err)
return
}

View file

@ -131,41 +131,41 @@ var (
thirdPartySyncCheckTicker = time.NewTicker(time.Minute * 10)
)
func ReportFileSysFatalError(err error) {
stack := debug.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)
}
func CheckFileSysStatus() {
if ContainerStd != Container {
return
}
reportFileSysFatalError := func(err error) {
stack := debug.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)
}
const fileSysStatusCheckFile = ".siyuan/filesys_status_check"
for {
<-thirdPartySyncCheckTicker.C
if IsCloudDrivePath(WorkspaceDir) {
reportFileSysFatalError(fmt.Errorf("workspace dir [%s] is in third party sync dir", WorkspaceDir))
continue
ReportFileSysFatalError(fmt.Errorf("workspace dir [%s] is in third party sync dir", WorkspaceDir))
return
}
dir := filepath.Join(DataDir, fileSysStatusCheckFile)
if err := os.RemoveAll(dir); nil != err {
reportFileSysFatalError(err)
continue
ReportFileSysFatalError(err)
return
}
if err := os.MkdirAll(dir, 0755); nil != err {
reportFileSysFatalError(err)
continue
ReportFileSysFatalError(err)
return
}
for i := 0; i < 7; i++ {
@ -173,13 +173,13 @@ func CheckFileSysStatus() {
data := make([]byte, 1024*4)
_, err := rand.Read(data)
if nil != err {
reportFileSysFatalError(err)
break
ReportFileSysFatalError(err)
return
}
if err = os.WriteFile(tmp, data, 0644); nil != err {
reportFileSysFatalError(err)
break
ReportFileSysFatalError(err)
return
}
time.Sleep(5 * time.Second)
@ -187,7 +187,7 @@ func CheckFileSysStatus() {
for j := 0; j < 32; j++ {
renamed := tmp + "_renamed"
if err = os.Rename(tmp, renamed); nil != err {
reportFileSysFatalError(err)
ReportFileSysFatalError(err)
break
}
@ -195,24 +195,24 @@ func CheckFileSysStatus() {
f, err := os.Open(renamed)
if nil != err {
reportFileSysFatalError(err)
break
ReportFileSysFatalError(err)
return
}
if err = f.Close(); nil != err {
reportFileSysFatalError(err)
break
ReportFileSysFatalError(err)
return
}
if err = os.Rename(renamed, tmp); nil != err {
reportFileSysFatalError(err)
break
ReportFileSysFatalError(err)
return
}
entries, err := os.ReadDir(dir)
if nil != err {
reportFileSysFatalError(err)
break
ReportFileSysFatalError(err)
return
}
checkFilenames := bytes.Buffer{}
@ -231,14 +231,14 @@ func CheckFileSysStatus() {
buf.WriteString("\n")
}
output := buf.String()
reportFileSysFatalError(fmt.Errorf("dir [%s] has more than 1 file:\n%s", dir, output))
break
ReportFileSysFatalError(fmt.Errorf("dir [%s] has more than 1 file:\n%s", dir, output))
return
}
}
if err = os.RemoveAll(tmp); nil != err {
reportFileSysFatalError(err)
break
ReportFileSysFatalError(err)
return
}
}