Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: 移动端支持多工作空间 https://github.com/siyuan-note/siyuan/issues/4642

Liang Dingac03db15dfd3
diff --git a/kernel/util/runtime.go b/kernel/util/runtime.go
index 4b971c6192..6d230bc9d4 100644
--- a/kernel/util/runtime.go
+++ b/kernel/util/runtime.go
@@ -32,13 +32,14 @@ import (
const DatabaseVer = "20220501" // 修改表结构的话需要修改这里
const (
- ExitCodeReadOnlyDatabase = 20 // 数据库文件被锁
- ExitCodeUnavailablePort = 21 // 端口不可用
- ExitCodeCreateConfDirErr = 22 // 创建配置目录失败
- ExitCodeBlockTreeErr = 23 // 无法读写 blocktree.msgpack 文件
- ExitCodeWorkspaceLocked = 24 // 工作空间已被锁定
- ExitCodeOk = 0 // 正常退出
- ExitCodeFatal = 1 // 致命错误
+ ExitCodeReadOnlyDatabase = 20 // 数据库文件被锁
+ ExitCodeUnavailablePort = 21 // 端口不可用
+ ExitCodeCreateConfDirErr = 22 // 创建配置目录失败
+ ExitCodeBlockTreeErr = 23 // 无法读写 blocktree.msgpack 文件
+ ExitCodeWorkspaceLocked = 24 // 工作空间已被锁定
+ ExitCodeCreateWorkspaceDirErr = 25 // 创建工作空间失败
+ ExitCodeOk = 0 // 正常退出
+ ExitCodeFatal = 1 // 致命错误
)
func logBootInfo() {
diff --git a/kernel/util/working.go b/kernel/util/working.go
index 50cfc10118..6ac71d81a7 100644
--- a/kernel/util/working.go
+++ b/kernel/util/working.go
@@ -199,6 +199,10 @@ func initWorkspaceDir(workspaceArg string) {
defaultWorkspaceDir = filepath.Join(userProfile, "Documents", "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(ExitCodeCreateWorkspaceDirErr)
+ }
var workspacePaths []string
if !gulu.File.IsExist(workspaceConf) {
diff --git a/kernel/util/working_mobile.go b/kernel/util/working_mobile.go
index 9b6d3561ea..bae5e71e83 100644
--- a/kernel/util/working_mobile.go
+++ b/kernel/util/working_mobile.go
@@ -45,7 +45,17 @@ func BootMobile(container, appDir, workspaceBaseDir, lang string) {
HomeDir = filepath.Join(workspaceBaseDir, "home")
userHomeConfDir := filepath.Join(HomeDir, ".config", "siyuan")
if !gulu.File.IsExist(userHomeConfDir) {
- os.MkdirAll(userHomeConfDir, 0755)
+ 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(ExitCodeCreateConfDirErr)
+ }
+
+ }
+
+ 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(ExitCodeCreateWorkspaceDirErr)
}
initWorkspaceDirMobile(workspaceBaseDir)
@@ -57,16 +67,52 @@ func BootMobile(container, appDir, workspaceBaseDir, lang string) {
}
func initWorkspaceDirMobile(workspaceBaseDir string) {
- userHomeConfDir := filepath.Join(HomeDir, ".config", "siyuan")
- workspaceConf := filepath.Join(userHomeConfDir, "workspace.json")
- 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(ExitCodeCreateConfDirErr)
+ if gulu.File.IsDir(workspaceBaseDir) {
+ entries, err := os.ReadDir(workspaceBaseDir)
+ if nil != err {
+ log.Printf("read workspace dir [%s] failed: %s", workspaceBaseDir, err)
+ } else {
+ // 旧版 iOS 端会在 workspaceBaseDir 下直接创建工作空间,这里需要将数据迁移到 workspaceBaseDir/siyuan/ 文件夹下
+ var oldConf, oldData, oldTemp bool
+ for _, entry := range entries {
+ if entry.IsDir() && "conf" == entry.Name() {
+ oldConf = true
+ continue
+ }
+ if entry.IsDir() && "data" == entry.Name() {
+ oldData = true
+ continue
+ }
+ if entry.IsDir() && "temp" == entry.Name() {
+ oldTemp = true
+ continue
+ }
+ }
+ if oldConf && oldData && oldTemp {
+ for _, entry := range entries {
+ if "home" == entry.Name() {
+ continue
+ }
+
+ 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)
+ } else {
+ log.Printf("moved workspace dir [fomr=%s, to=%s]", from, to)
+ }
+ }
+
+ os.RemoveAll(filepath.Join(workspaceBaseDir, "sync"))
+ os.RemoveAll(filepath.Join(workspaceBaseDir, "backup"))
+ }
}
}
+ userHomeConfDir := filepath.Join(HomeDir, ".config", "siyuan")
+ workspaceConf := filepath.Join(userHomeConfDir, "workspace.json")
defaultWorkspaceDir := filepath.Join(workspaceBaseDir, "siyuan")
+
var workspacePaths []string
if !gulu.File.IsExist(workspaceConf) {
WorkspaceDir = defaultWorkspaceDir