🎨 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>
This commit is contained in:
Daniel 2025-09-29 11:27:00 +08:00
parent fa17345793
commit f05f56b3e8
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
15 changed files with 65 additions and 41 deletions

View file

@ -43,6 +43,28 @@ func checkWorkspaceDir(c *gin.Context) {
}
path := arg["path"].(string)
// 检查路径是否是分区根路径
if util.IsPartitionRootPath(path) {
ret.Code = -1
ret.Msg = model.Conf.Language(273)
ret.Data = map[string]interface{}{"closeTimeout": 7000}
return
}
// 检查路径是否包含其他文件
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) {
ret.Code = -1
ret.Msg = "This workspace name is not allowed, please use another name"
@ -55,32 +77,8 @@ func checkWorkspaceDir(c *gin.Context) {
return
}
entries, err := os.ReadDir(path)
if err != nil {
ret.Code = -1
ret.Msg = fmt.Sprintf("read workspace dir [%s] failed: %s", path, err)
}
var existsConf, existsData bool
for _, entry := range entries {
if !existsConf {
existsConf = "conf" == entry.Name() && entry.IsDir()
}
if !existsData {
existsData = "data" == entry.Name() && entry.IsDir()
}
if existsConf && existsData {
break
}
}
if existsConf {
existsConf = gulu.File.IsExist(filepath.Join(path, "conf", "conf.json"))
}
ret.Data = map[string]interface{}{
"isWorkspace": existsConf && existsData,
"isWorkspace": util.IsWorkspaceDir(path),
}
}
@ -300,7 +298,7 @@ func setWorkspaceDir(c *gin.Context) {
// 检查路径是否在已有的工作空间路径中
pathIsWorkspace := util.IsWorkspaceDir(path)
if !pathIsWorkspace {
for p := filepath.Dir(path); !util.IsRootPath(p); p = filepath.Dir(p) {
for p := filepath.Dir(path); !util.IsPartitionRootPath(p); p = filepath.Dir(p) {
if util.IsWorkspaceDir(p) {
ret.Code = -1
ret.Msg = fmt.Sprintf(model.Conf.Language(256), path, p)