mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-20 23:36:10 +01:00
🎨 增加 kernel.log https://github.com/siyuan-note/siyuan/issues/7789
This commit is contained in:
parent
f534675464
commit
a85c61d3c1
7 changed files with 57 additions and 39 deletions
|
|
@ -244,12 +244,11 @@ func checkFileSysStatus() {
|
|||
}
|
||||
|
||||
func IsCloudDrivePath(workspaceAbsPath string) bool {
|
||||
absPathLower := strings.ToLower(workspaceAbsPath)
|
||||
if isICloudPath(absPathLower) {
|
||||
if isICloudPath(workspaceAbsPath) {
|
||||
return true
|
||||
}
|
||||
|
||||
if isKnownCloudDrivePath(absPathLower) {
|
||||
if isKnownCloudDrivePath(workspaceAbsPath) {
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
@ -260,17 +259,20 @@ func IsCloudDrivePath(workspaceAbsPath string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func isKnownCloudDrivePath(workspaceAbsPathLower string) bool {
|
||||
func isKnownCloudDrivePath(workspaceAbsPath string) bool {
|
||||
workspaceAbsPathLower := strings.ToLower(workspaceAbsPath)
|
||||
return strings.Contains(workspaceAbsPathLower, "onedrive") || strings.Contains(workspaceAbsPathLower, "dropbox") ||
|
||||
strings.Contains(workspaceAbsPathLower, "google drive") || strings.Contains(workspaceAbsPathLower, "pcloud") ||
|
||||
strings.Contains(workspaceAbsPathLower, "坚果云")
|
||||
}
|
||||
|
||||
func isICloudPath(workspaceAbsPathLower string) (ret bool) {
|
||||
func isICloudPath(workspaceAbsPath string) (ret bool) {
|
||||
if !gulu.OS.IsDarwin() {
|
||||
return false
|
||||
}
|
||||
|
||||
workspaceAbsPathLower := strings.ToLower(workspaceAbsPath)
|
||||
|
||||
// macOS 端对工作空间放置在 iCloud 路径下做检查 https://github.com/siyuan-note/siyuan/issues/7747
|
||||
iCloudRoot := filepath.Join(HomeDir, "Library", "Mobile Documents")
|
||||
WalkWithSymlinks(iCloudRoot, func(path string, info os.FileInfo, err error) error {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import (
|
|||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"mime"
|
||||
"os"
|
||||
|
|
@ -186,10 +185,12 @@ var (
|
|||
func initWorkspaceDir(workspaceArg string) {
|
||||
userHomeConfDir := filepath.Join(HomeDir, ".config", "siyuan")
|
||||
workspaceConf := filepath.Join(userHomeConfDir, "workspace.json")
|
||||
logging.SetLogPath(filepath.Join(userHomeConfDir, "kernel.log"))
|
||||
|
||||
if !gulu.File.IsExist(workspaceConf) {
|
||||
if err := os.MkdirAll(userHomeConfDir, 0755); nil != err && !os.IsExist(err) {
|
||||
log.Printf("create user home conf folder [%s] failed: %s", userHomeConfDir, err)
|
||||
os.Exit(logging.ExitCodeCreateConfDirErr)
|
||||
logging.LogErrorf("create user home conf folder [%s] failed: %s", userHomeConfDir, err)
|
||||
os.Exit(logging.ExitCodeInitWorkspaceErr)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -201,8 +202,8 @@ func initWorkspaceDir(workspaceArg string) {
|
|||
}
|
||||
}
|
||||
if err := os.MkdirAll(defaultWorkspaceDir, 0755); nil != err && !os.IsExist(err) {
|
||||
log.Printf("create default workspace folder [%s] failed: %s", defaultWorkspaceDir, err)
|
||||
os.Exit(logging.ExitCodeCreateWorkspaceDirErr)
|
||||
logging.LogErrorf("create default workspace folder [%s] failed: %s", defaultWorkspaceDir, err)
|
||||
os.Exit(logging.ExitCodeInitWorkspaceErr)
|
||||
}
|
||||
|
||||
var workspacePaths []string
|
||||
|
|
@ -226,13 +227,14 @@ func initWorkspaceDir(workspaceArg string) {
|
|||
}
|
||||
|
||||
if !gulu.File.IsDir(WorkspaceDir) {
|
||||
log.Printf("use the default workspace [%s] since the specified workspace [%s] is not a dir", WorkspaceDir, defaultWorkspaceDir)
|
||||
logging.LogWarnf("use the default workspace [%s] since the specified workspace [%s] is not a dir", WorkspaceDir, defaultWorkspaceDir)
|
||||
WorkspaceDir = defaultWorkspaceDir
|
||||
}
|
||||
workspacePaths = append(workspacePaths, WorkspaceDir)
|
||||
|
||||
if err := WriteWorkspacePaths(workspacePaths); nil != err {
|
||||
log.Fatalf("write workspace conf [%s] failed: %s", workspaceConf, err)
|
||||
logging.LogErrorf("write workspace conf [%s] failed: %s", workspaceConf, err)
|
||||
os.Exit(logging.ExitCodeInitWorkspaceErr)
|
||||
}
|
||||
|
||||
ConfDir = filepath.Join(WorkspaceDir, "conf")
|
||||
|
|
@ -243,7 +245,8 @@ func initWorkspaceDir(workspaceArg string) {
|
|||
osTmpDir := filepath.Join(TempDir, "os")
|
||||
os.RemoveAll(osTmpDir)
|
||||
if err := os.MkdirAll(osTmpDir, 0755); nil != err {
|
||||
log.Fatalf("create os tmp dir [%s] failed: %s", osTmpDir, err)
|
||||
logging.LogErrorf("create os tmp dir [%s] failed: %s", osTmpDir, err)
|
||||
os.Exit(logging.ExitCodeInitWorkspaceErr)
|
||||
}
|
||||
os.RemoveAll(filepath.Join(TempDir, "repo"))
|
||||
os.Setenv("TMPDIR", osTmpDir)
|
||||
|
|
@ -327,33 +330,33 @@ const (
|
|||
|
||||
func initPathDir() {
|
||||
if err := os.MkdirAll(ConfDir, 0755); nil != err && !os.IsExist(err) {
|
||||
log.Fatalf("create conf folder [%s] failed: %s", ConfDir, err)
|
||||
logging.LogFatalf(logging.ExitCodeInitWorkspaceErr, "create conf folder [%s] failed: %s", ConfDir, err)
|
||||
}
|
||||
if err := os.MkdirAll(DataDir, 0755); nil != err && !os.IsExist(err) {
|
||||
log.Fatalf("create data folder [%s] failed: %s", DataDir, err)
|
||||
logging.LogFatalf(logging.ExitCodeInitWorkspaceErr, "create data folder [%s] failed: %s", DataDir, err)
|
||||
}
|
||||
if err := os.MkdirAll(TempDir, 0755); nil != err && !os.IsExist(err) {
|
||||
log.Fatalf("create temp folder [%s] failed: %s", TempDir, err)
|
||||
logging.LogFatalf(logging.ExitCodeInitWorkspaceErr, "create temp folder [%s] failed: %s", TempDir, err)
|
||||
}
|
||||
|
||||
assets := filepath.Join(DataDir, "assets")
|
||||
if err := os.MkdirAll(assets, 0755); nil != err && !os.IsExist(err) {
|
||||
log.Fatalf("create data assets folder [%s] failed: %s", assets, err)
|
||||
logging.LogFatalf(logging.ExitCodeInitWorkspaceErr, "create data assets folder [%s] failed: %s", assets, err)
|
||||
}
|
||||
|
||||
templates := filepath.Join(DataDir, "templates")
|
||||
if err := os.MkdirAll(templates, 0755); nil != err && !os.IsExist(err) {
|
||||
log.Fatalf("create data templates folder [%s] failed: %s", templates, err)
|
||||
logging.LogFatalf(logging.ExitCodeInitWorkspaceErr, "create data templates folder [%s] failed: %s", templates, err)
|
||||
}
|
||||
|
||||
widgets := filepath.Join(DataDir, "widgets")
|
||||
if err := os.MkdirAll(widgets, 0755); nil != err && !os.IsExist(err) {
|
||||
log.Fatalf("create data widgets folder [%s] failed: %s", widgets, err)
|
||||
logging.LogFatalf(logging.ExitCodeInitWorkspaceErr, "create data widgets folder [%s] failed: %s", widgets, err)
|
||||
}
|
||||
|
||||
emojis := filepath.Join(DataDir, "emojis")
|
||||
if err := os.MkdirAll(emojis, 0755); nil != err && !os.IsExist(err) {
|
||||
log.Fatalf("create data emojis folder [%s] failed: %s", widgets, err)
|
||||
logging.LogFatalf(logging.ExitCodeInitWorkspaceErr, "create data emojis folder [%s] failed: %s", widgets, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -43,18 +42,20 @@ func BootMobile(container, appDir, workspaceBaseDir, lang string) {
|
|||
WorkingDir = filepath.Join(appDir, "app")
|
||||
HomeDir = filepath.Join(workspaceBaseDir, "home")
|
||||
userHomeConfDir := filepath.Join(HomeDir, ".config", "siyuan")
|
||||
logging.SetLogPath(filepath.Join(userHomeConfDir, "kernel.log"))
|
||||
|
||||
if !gulu.File.IsExist(userHomeConfDir) {
|
||||
if err := os.MkdirAll(userHomeConfDir, 0755); nil != err && !os.IsExist(err) {
|
||||
log.Printf("create user home conf folder [%s] failed: %s", userHomeConfDir, err)
|
||||
os.Exit(logging.ExitCodeCreateConfDirErr)
|
||||
logging.LogErrorf("create user home conf folder [%s] failed: %s", userHomeConfDir, err)
|
||||
os.Exit(logging.ExitCodeInitWorkspaceErr)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
defaultWorkspaceDir := filepath.Join(workspaceBaseDir, "siyuan")
|
||||
if err := os.MkdirAll(defaultWorkspaceDir, 0755); nil != err && !os.IsExist(err) {
|
||||
log.Printf("create default workspace folder [%s] failed: %s", defaultWorkspaceDir, err)
|
||||
os.Exit(logging.ExitCodeCreateWorkspaceDirErr)
|
||||
logging.LogErrorf("create default workspace folder [%s] failed: %s", defaultWorkspaceDir, err)
|
||||
os.Exit(logging.ExitCodeInitWorkspaceErr)
|
||||
}
|
||||
|
||||
initWorkspaceDirMobile(workspaceBaseDir)
|
||||
|
|
@ -69,7 +70,7 @@ func initWorkspaceDirMobile(workspaceBaseDir string) {
|
|||
if gulu.File.IsDir(workspaceBaseDir) {
|
||||
entries, err := os.ReadDir(workspaceBaseDir)
|
||||
if nil != err {
|
||||
log.Printf("read workspace dir [%s] failed: %s", workspaceBaseDir, err)
|
||||
logging.LogErrorf("read workspace dir [%s] failed: %s", workspaceBaseDir, err)
|
||||
} else {
|
||||
// 旧版 iOS 端会在 workspaceBaseDir 下直接创建工作空间,这里需要将数据迁移到 workspaceBaseDir/siyuan/ 文件夹下
|
||||
var oldConf, oldData, oldTemp bool
|
||||
|
|
@ -96,9 +97,9 @@ func initWorkspaceDirMobile(workspaceBaseDir string) {
|
|||
from := filepath.Join(workspaceBaseDir, entry.Name())
|
||||
to := filepath.Join(workspaceBaseDir, "siyuan", entry.Name())
|
||||
if err = os.Rename(from, to); nil != err {
|
||||
log.Printf("move workspace dir [%s] failed: %s", workspaceBaseDir, err)
|
||||
logging.LogErrorf("move workspace dir [%s] failed: %s", workspaceBaseDir, err)
|
||||
} else {
|
||||
log.Printf("moved workspace dir [fomr=%s, to=%s]", from, to)
|
||||
logging.LogInfof("moved workspace dir [fomr=%s, to=%s]", from, to)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -116,7 +117,7 @@ func initWorkspaceDirMobile(workspaceBaseDir string) {
|
|||
if !gulu.File.IsExist(workspaceConf) {
|
||||
WorkspaceDir = defaultWorkspaceDir
|
||||
if !gulu.File.IsDir(WorkspaceDir) {
|
||||
log.Printf("use the default workspace [%s] since the specified workspace [%s] is not a dir", WorkspaceDir, defaultWorkspaceDir)
|
||||
logging.LogWarnf("use the default workspace [%s] since the specified workspace [%s] is not a dir", WorkspaceDir, defaultWorkspaceDir)
|
||||
WorkspaceDir = defaultWorkspaceDir
|
||||
}
|
||||
workspacePaths = append(workspacePaths, WorkspaceDir)
|
||||
|
|
@ -125,7 +126,7 @@ func initWorkspaceDirMobile(workspaceBaseDir string) {
|
|||
if 0 < len(workspacePaths) {
|
||||
WorkspaceDir = workspacePaths[len(workspacePaths)-1]
|
||||
if !gulu.File.IsDir(WorkspaceDir) {
|
||||
log.Printf("use the default workspace [%s] since the specified workspace [%s] is not a dir", defaultWorkspaceDir, WorkspaceDir)
|
||||
logging.LogWarnf("use the default workspace [%s] since the specified workspace [%s] is not a dir", defaultWorkspaceDir, WorkspaceDir)
|
||||
WorkspaceDir = defaultWorkspaceDir
|
||||
}
|
||||
workspacePaths[len(workspacePaths)-1] = WorkspaceDir
|
||||
|
|
@ -136,7 +137,8 @@ func initWorkspaceDirMobile(workspaceBaseDir string) {
|
|||
}
|
||||
|
||||
if err := WriteWorkspacePaths(workspacePaths); nil != err {
|
||||
log.Fatalf("write workspace conf [%s] failed: %s", workspaceConf, err)
|
||||
logging.LogErrorf("write workspace conf [%s] failed: %s", workspaceConf, err)
|
||||
os.Exit(logging.ExitCodeInitWorkspaceErr)
|
||||
}
|
||||
|
||||
ConfDir = filepath.Join(WorkspaceDir, "conf")
|
||||
|
|
@ -147,7 +149,8 @@ func initWorkspaceDirMobile(workspaceBaseDir string) {
|
|||
osTmpDir := filepath.Join(TempDir, "os")
|
||||
os.RemoveAll(osTmpDir)
|
||||
if err := os.MkdirAll(osTmpDir, 0755); nil != err {
|
||||
log.Fatalf("create os tmp dir [%s] failed: %s", osTmpDir, err)
|
||||
logging.LogErrorf("create os tmp dir [%s] failed: %s", osTmpDir, err)
|
||||
os.Exit(logging.ExitCodeInitWorkspaceErr)
|
||||
}
|
||||
os.RemoveAll(filepath.Join(TempDir, "repo"))
|
||||
os.Setenv("TMPDIR", osTmpDir)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue