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
2af8b67cbd
commit
f9520e3a08
4 changed files with 59 additions and 43 deletions
|
|
@ -35,13 +35,17 @@ import (
|
||||||
func InitAppearance() {
|
func InitAppearance() {
|
||||||
util.SetBootDetails("Initializing appearance...")
|
util.SetBootDetails("Initializing appearance...")
|
||||||
if err := os.Mkdir(util.AppearancePath, 0755); nil != err && !os.IsExist(err) {
|
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()
|
unloadThemes()
|
||||||
from := filepath.Join(util.WorkingDir, "appearance")
|
from := filepath.Join(util.WorkingDir, "appearance")
|
||||||
if err := gulu.File.Copy(from, util.AppearancePath); nil != err {
|
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()
|
loadThemes()
|
||||||
|
|
||||||
|
|
@ -95,7 +99,9 @@ func unloadThemes() {
|
||||||
func loadThemes() {
|
func loadThemes() {
|
||||||
themeDirs, err := os.ReadDir(util.ThemesPath)
|
themeDirs, err := os.ReadDir(util.ThemesPath)
|
||||||
if nil != err {
|
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
|
Conf.Appearance.DarkThemes = nil
|
||||||
|
|
@ -204,7 +210,9 @@ func widgetJSON(widgetName string) (ret map[string]interface{}, err error) {
|
||||||
func loadIcons() {
|
func loadIcons() {
|
||||||
iconDirs, err := os.ReadDir(util.IconsPath)
|
iconDirs, err := os.ReadDir(util.IconsPath)
|
||||||
if nil != err {
|
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
|
Conf.Appearance.Icons = nil
|
||||||
|
|
|
||||||
|
|
@ -343,13 +343,17 @@ func initLang() {
|
||||||
p := filepath.Join(util.WorkingDir, "appearance", "langs")
|
p := filepath.Join(util.WorkingDir, "appearance", "langs")
|
||||||
dir, err := os.Open(p)
|
dir, err := os.Open(p)
|
||||||
if nil != err {
|
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()
|
defer dir.Close()
|
||||||
|
|
||||||
langNames, err := dir.Readdirnames(-1)
|
langNames, err := dir.Readdirnames(-1)
|
||||||
if nil != err {
|
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 {
|
for _, langName := range langNames {
|
||||||
|
|
@ -510,7 +514,9 @@ func (conf *AppConf) Save() {
|
||||||
func (conf *AppConf) save0(data []byte) {
|
func (conf *AppConf) save0(data []byte) {
|
||||||
confPath := filepath.Join(util.ConfDir, "conf.json")
|
confPath := filepath.Join(util.ConfDir, "conf.json")
|
||||||
if err := filelock.WriteFile(confPath, data); nil != err {
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -217,12 +217,14 @@ func serveAppearance(ginServer *gin.Engine) {
|
||||||
enUSFilePath := filepath.Join(appearancePath, "langs", "en_US.json")
|
enUSFilePath := filepath.Join(appearancePath, "langs", "en_US.json")
|
||||||
enUSData, err := os.ReadFile(enUSFilePath)
|
enUSData, err := os.ReadFile(enUSFilePath)
|
||||||
if nil != err {
|
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
|
return
|
||||||
}
|
}
|
||||||
enUSMap := map[string]interface{}{}
|
enUSMap := map[string]interface{}{}
|
||||||
if err = gulu.JSON.UnmarshalJSON(enUSData, &enUSMap); nil != err {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -131,41 +131,41 @@ var (
|
||||||
thirdPartySyncCheckTicker = time.NewTicker(time.Minute * 10)
|
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() {
|
func CheckFileSysStatus() {
|
||||||
if ContainerStd != Container {
|
if ContainerStd != Container {
|
||||||
return
|
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"
|
const fileSysStatusCheckFile = ".siyuan/filesys_status_check"
|
||||||
|
|
||||||
for {
|
for {
|
||||||
<-thirdPartySyncCheckTicker.C
|
<-thirdPartySyncCheckTicker.C
|
||||||
|
|
||||||
if IsCloudDrivePath(WorkspaceDir) {
|
if IsCloudDrivePath(WorkspaceDir) {
|
||||||
reportFileSysFatalError(fmt.Errorf("workspace dir [%s] is in third party sync dir", WorkspaceDir))
|
ReportFileSysFatalError(fmt.Errorf("workspace dir [%s] is in third party sync dir", WorkspaceDir))
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dir := filepath.Join(DataDir, fileSysStatusCheckFile)
|
dir := filepath.Join(DataDir, fileSysStatusCheckFile)
|
||||||
if err := os.RemoveAll(dir); nil != err {
|
if err := os.RemoveAll(dir); nil != err {
|
||||||
reportFileSysFatalError(err)
|
ReportFileSysFatalError(err)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.MkdirAll(dir, 0755); nil != err {
|
if err := os.MkdirAll(dir, 0755); nil != err {
|
||||||
reportFileSysFatalError(err)
|
ReportFileSysFatalError(err)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < 7; i++ {
|
for i := 0; i < 7; i++ {
|
||||||
|
|
@ -173,13 +173,13 @@ func CheckFileSysStatus() {
|
||||||
data := make([]byte, 1024*4)
|
data := make([]byte, 1024*4)
|
||||||
_, err := rand.Read(data)
|
_, err := rand.Read(data)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
reportFileSysFatalError(err)
|
ReportFileSysFatalError(err)
|
||||||
break
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = os.WriteFile(tmp, data, 0644); nil != err {
|
if err = os.WriteFile(tmp, data, 0644); nil != err {
|
||||||
reportFileSysFatalError(err)
|
ReportFileSysFatalError(err)
|
||||||
break
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
|
|
@ -187,7 +187,7 @@ func CheckFileSysStatus() {
|
||||||
for j := 0; j < 32; j++ {
|
for j := 0; j < 32; j++ {
|
||||||
renamed := tmp + "_renamed"
|
renamed := tmp + "_renamed"
|
||||||
if err = os.Rename(tmp, renamed); nil != err {
|
if err = os.Rename(tmp, renamed); nil != err {
|
||||||
reportFileSysFatalError(err)
|
ReportFileSysFatalError(err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -195,24 +195,24 @@ func CheckFileSysStatus() {
|
||||||
|
|
||||||
f, err := os.Open(renamed)
|
f, err := os.Open(renamed)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
reportFileSysFatalError(err)
|
ReportFileSysFatalError(err)
|
||||||
break
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = f.Close(); nil != err {
|
if err = f.Close(); nil != err {
|
||||||
reportFileSysFatalError(err)
|
ReportFileSysFatalError(err)
|
||||||
break
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = os.Rename(renamed, tmp); nil != err {
|
if err = os.Rename(renamed, tmp); nil != err {
|
||||||
reportFileSysFatalError(err)
|
ReportFileSysFatalError(err)
|
||||||
break
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
entries, err := os.ReadDir(dir)
|
entries, err := os.ReadDir(dir)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
reportFileSysFatalError(err)
|
ReportFileSysFatalError(err)
|
||||||
break
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
checkFilenames := bytes.Buffer{}
|
checkFilenames := bytes.Buffer{}
|
||||||
|
|
@ -231,14 +231,14 @@ func CheckFileSysStatus() {
|
||||||
buf.WriteString("\n")
|
buf.WriteString("\n")
|
||||||
}
|
}
|
||||||
output := buf.String()
|
output := buf.String()
|
||||||
reportFileSysFatalError(fmt.Errorf("dir [%s] has more than 1 file:\n%s", dir, output))
|
ReportFileSysFatalError(fmt.Errorf("dir [%s] has more than 1 file:\n%s", dir, output))
|
||||||
break
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = os.RemoveAll(tmp); nil != err {
|
if err = os.RemoveAll(tmp); nil != err {
|
||||||
reportFileSysFatalError(err)
|
ReportFileSysFatalError(err)
|
||||||
break
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue