mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-02 22:21:28 +08:00
🎨 改进判断工作空间路径实现 Fix https://github.com/siyuan-note/siyuan/issues/7569
This commit is contained in:
parent
0f15fd2550
commit
3c9e80b411
@ -198,8 +198,10 @@ func setWorkspaceDir(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if gulu.OS.IsWindows() {
|
if gulu.OS.IsWindows() {
|
||||||
installDir := filepath.Dir(util.WorkingDir)
|
// 改进判断工作空间路径实现 https://github.com/siyuan-note/siyuan/issues/7569
|
||||||
if strings.HasPrefix(path, installDir) {
|
installDirLower := strings.ToLower(filepath.Dir(util.WorkingDir))
|
||||||
|
pathLower := strings.ToLower(path)
|
||||||
|
if strings.HasPrefix(pathLower, installDirLower) && util.IsSubPath(installDirLower, pathLower) {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = model.Conf.Language(98)
|
ret.Msg = model.Conf.Language(98)
|
||||||
ret.Data = map[string]interface{}{"closeTimeout": 5000}
|
ret.Data = map[string]interface{}{"closeTimeout": 5000}
|
||||||
|
@ -148,13 +148,13 @@ func FilterFileName(name string) string {
|
|||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsSubFolder(parent, sub string) bool {
|
func IsSubPath(absPath, toCheckPath string) bool {
|
||||||
if 1 > len(parent) || 1 > len(sub) {
|
if 1 > len(absPath) || 1 > len(toCheckPath) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if gulu.OS.IsWindows() {
|
if gulu.OS.IsWindows() {
|
||||||
if filepath.IsAbs(parent) && filepath.IsAbs(sub) {
|
if filepath.IsAbs(absPath) && filepath.IsAbs(toCheckPath) {
|
||||||
if strings.ToLower(parent)[0] != strings.ToLower(sub)[0] {
|
if strings.ToLower(absPath)[0] != strings.ToLower(toCheckPath)[0] {
|
||||||
// 不在一个盘
|
// 不在一个盘
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -162,7 +162,7 @@ func IsSubFolder(parent, sub string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
up := ".." + string(os.PathSeparator)
|
up := ".." + string(os.PathSeparator)
|
||||||
rel, err := filepath.Rel(parent, sub)
|
rel, err := filepath.Rel(absPath, toCheckPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user