mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-07 17:28:50 +01:00
🎨 Improve workspace dir checking https://github.com/siyuan-note/siyuan/issues/13789
This commit is contained in:
parent
0ba7a47472
commit
b6ef8be3d5
14 changed files with 47 additions and 12 deletions
|
|
@ -297,6 +297,19 @@ func setWorkspaceDir(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
// 检查路径是否在已有的工作空间路径中
|
||||
pathIsWorkspace := util.IsWorkspaceDir(path)
|
||||
if !pathIsWorkspace {
|
||||
for p := filepath.Dir(path); "" != p; p = filepath.Dir(p) {
|
||||
if util.IsWorkspaceDir(p) {
|
||||
ret.Code = -1
|
||||
ret.Msg = fmt.Sprintf(model.Conf.Language(256), path, p)
|
||||
ret.Data = map[string]interface{}{"closeTimeout": 7000}
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
workspacePaths, err := util.ReadWorkspacePaths()
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
|
|
|
|||
|
|
@ -341,3 +341,13 @@ func GetAbsPathInWorkspace(relPath string) (string, error) {
|
|||
func IsAbsPathInWorkspace(absPath string) bool {
|
||||
return IsSubPath(WorkspaceDir, absPath)
|
||||
}
|
||||
|
||||
// IsWorkspaceDir 判断指定目录是否是工作空间目录。
|
||||
func IsWorkspaceDir(dir string) bool {
|
||||
conf := filepath.Join(dir, "conf", "conf.json")
|
||||
data, err := os.ReadFile(conf)
|
||||
if nil != err {
|
||||
return false
|
||||
}
|
||||
return strings.Contains(string(data), "kernelVersion")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue