From 33216b093dfbc979bacb544571c1335ed6887c03 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 29 Sep 2025 11:34:24 +0800 Subject: [PATCH 1/2] :art: Prompt when the user attempts to create a workspace in the root directory of the disk https://github.com/siyuan-note/siyuan/issues/15976 Signed-off-by: Daniel <845765@qq.com> --- kernel/api/workspace.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/kernel/api/workspace.go b/kernel/api/workspace.go index 81d0318e9..b1fbddd98 100644 --- a/kernel/api/workspace.go +++ b/kernel/api/workspace.go @@ -52,17 +52,19 @@ func checkWorkspaceDir(c *gin.Context) { } // 检查路径是否包含其他文件 - entries, err := os.ReadDir(path) - if err != nil { - ret.Code = -1 - ret.Msg = fmt.Sprintf("read dir [%s] failed: %s", path, err) - return - } - if 0 < len(entries) { - ret.Code = -1 - ret.Msg = model.Conf.Language(274) - ret.Data = map[string]interface{}{"closeTimeout": 7000} - return + if !util.IsWorkspaceDir(path) { + entries, err := os.ReadDir(path) + if err != nil { + ret.Code = -1 + ret.Msg = fmt.Sprintf("read dir [%s] failed: %s", path, err) + return + } + if 0 < len(entries) { + ret.Code = -1 + ret.Msg = model.Conf.Language(274) + ret.Data = map[string]interface{}{"closeTimeout": 7000} + return + } } if isInvalidWorkspacePath(path) { From dbf5a3e198bfcce3136858a8a723aa9c6e4f99ad Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 29 Sep 2025 17:04:03 +0800 Subject: [PATCH 2/2] :art: Prompt when the user attempts to create a workspace in the root directory of the disk https://github.com/siyuan-note/siyuan/issues/15976 Signed-off-by: Daniel <845765@qq.com> --- app/electron/init.html | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/app/electron/init.html b/app/electron/init.html index 415196e4e..712d0eb93 100644 --- a/app/electron/init.html +++ b/app/electron/init.html @@ -383,6 +383,24 @@ } const initPath = result.filePaths[0] + if (isPartitionRootPath(initPath)) { + let msg = '⚠️ Do not create the workspace in the partition root path, please create a new folder as the workspace' + if (isChinese(currentLang)) { + msg = '⚠️ 请勿在分区根路径上创建工作空间,请新建一个文件夹作为工作空间' + } + alert(msg) + return + } + + if (!isWorkspaceDir(initPath) && !isEmptyDir(initPath)) { + let msg = '⚠️ This folder contains other files, please create a new folder as the workspace' + if (isChinese(currentLang)) { + msg = '⚠️ 该文件夹包含了其他文件,请新建一个文件夹作为工作空间' + } + alert(msg) + return + } + if (isICloudPath(initPath)) { let msg = '⚠️ This folder is under the iCloud sync path, please change another path' if (isChinese(currentLang)) { @@ -417,6 +435,36 @@ }) }) + const isPartitionRootPath = (absPath) => { + const path = require('path') + const parsedPath = path.parse(absPath) + return parsedPath.root === absPath + } + + const isEmptyDir = (absPath) => { + const fs = require('fs') + let files; + try { + files = fs.readdirSync(absPath) + } catch (err) { + return false + } + return 0 === files.length + } + + const isWorkspaceDir = (absPath) => { + const path = require('path'); + const fs = require('fs'); + const conf = path.join(absPath, 'conf', 'conf.json'); + let data; + try { + data = fs.readFileSync(conf, 'utf8'); + } catch (err) { + return false; + } + return data.includes('kernelVersion'); + } + const isCloudDrivePath = (absPath) => { const absPathLower = absPath.toLowerCase() return -1 < absPathLower.indexOf("onedrive") || -1 < absPathLower.indexOf("dropbox") ||