From 3c9e80b4117b5a97f11b33616ff3b734dcd9e711 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sat, 4 Mar 2023 18:11:17 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=94=B9=E8=BF=9B=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E7=A9=BA=E9=97=B4=E8=B7=AF=E5=BE=84=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=20Fix=20https://github.com/siyuan-note/siyuan/issues/?= =?UTF-8?q?7569?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/workspace.go | 6 ++++-- kernel/util/file.go | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/kernel/api/workspace.go b/kernel/api/workspace.go index fe2a4c145..3b6b1510c 100644 --- a/kernel/api/workspace.go +++ b/kernel/api/workspace.go @@ -198,8 +198,10 @@ func setWorkspaceDir(c *gin.Context) { } if gulu.OS.IsWindows() { - installDir := filepath.Dir(util.WorkingDir) - if strings.HasPrefix(path, installDir) { + // 改进判断工作空间路径实现 https://github.com/siyuan-note/siyuan/issues/7569 + installDirLower := strings.ToLower(filepath.Dir(util.WorkingDir)) + pathLower := strings.ToLower(path) + if strings.HasPrefix(pathLower, installDirLower) && util.IsSubPath(installDirLower, pathLower) { ret.Code = -1 ret.Msg = model.Conf.Language(98) ret.Data = map[string]interface{}{"closeTimeout": 5000} diff --git a/kernel/util/file.go b/kernel/util/file.go index f39ebe004..090956dcf 100644 --- a/kernel/util/file.go +++ b/kernel/util/file.go @@ -148,13 +148,13 @@ func FilterFileName(name string) string { return name } -func IsSubFolder(parent, sub string) bool { - if 1 > len(parent) || 1 > len(sub) { +func IsSubPath(absPath, toCheckPath string) bool { + if 1 > len(absPath) || 1 > len(toCheckPath) { return false } if gulu.OS.IsWindows() { - if filepath.IsAbs(parent) && filepath.IsAbs(sub) { - if strings.ToLower(parent)[0] != strings.ToLower(sub)[0] { + if filepath.IsAbs(absPath) && filepath.IsAbs(toCheckPath) { + if strings.ToLower(absPath)[0] != strings.ToLower(toCheckPath)[0] { // 不在一个盘 return false } @@ -162,7 +162,7 @@ func IsSubFolder(parent, sub string) bool { } up := ".." + string(os.PathSeparator) - rel, err := filepath.Rel(parent, sub) + rel, err := filepath.Rel(absPath, toCheckPath) if err != nil { return false }