mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
🎨 Improve workspace dir checking https://github.com/siyuan-note/siyuan/issues/13789
This commit is contained in:
parent
e01b7256b5
commit
010139be3f
2 changed files with 21 additions and 1 deletions
|
@ -300,7 +300,7 @@ func setWorkspaceDir(c *gin.Context) {
|
||||||
// 检查路径是否在已有的工作空间路径中
|
// 检查路径是否在已有的工作空间路径中
|
||||||
pathIsWorkspace := util.IsWorkspaceDir(path)
|
pathIsWorkspace := util.IsWorkspaceDir(path)
|
||||||
if !pathIsWorkspace {
|
if !pathIsWorkspace {
|
||||||
for p := filepath.Dir(path); "" != p; p = filepath.Dir(p) {
|
for p := filepath.Dir(path); !util.IsRootPath(p); p = filepath.Dir(p) {
|
||||||
if util.IsWorkspaceDir(p) {
|
if util.IsWorkspaceDir(p) {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = fmt.Sprintf(model.Conf.Language(256), path, p)
|
ret.Msg = fmt.Sprintf(model.Conf.Language(256), path, p)
|
||||||
|
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -351,3 +352,22 @@ func IsWorkspaceDir(dir string) bool {
|
||||||
}
|
}
|
||||||
return strings.Contains(string(data), "kernelVersion")
|
return strings.Contains(string(data), "kernelVersion")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsRootPath checks if the given path is a root path.
|
||||||
|
func IsRootPath(path string) bool {
|
||||||
|
if path == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean the path to remove any trailing slashes
|
||||||
|
cleanPath := filepath.Clean(path)
|
||||||
|
|
||||||
|
// Check if the path is the root path based on the operating system
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
// On Windows, root paths are like "C:\", "D:\", etc.
|
||||||
|
return len(cleanPath) == 3 && cleanPath[1] == ':' && cleanPath[2] == '\\'
|
||||||
|
} else {
|
||||||
|
// On Unix-like systems, the root path is "/"
|
||||||
|
return cleanPath == "/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue