From fc258a166e2aae1851d397ed1bf50abeb3b75417 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 23 Mar 2023 09:18:54 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20macOS=20=E7=AB=AF=E5=AF=B9=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E7=A9=BA=E9=97=B4=E6=94=BE=E7=BD=AE=E5=9C=A8=20iCloud?= =?UTF-8?q?=20=E8=B7=AF=E5=BE=84=E4=B8=8B=E5=81=9A=E6=A3=80=E6=9F=A5=20htt?= =?UTF-8?q?ps://github.com/siyuan-note/siyuan/issues/7747?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/util/runtime.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/kernel/util/runtime.go b/kernel/util/runtime.go index 6b545e6f9..deda6900d 100644 --- a/kernel/util/runtime.go +++ b/kernel/util/runtime.go @@ -19,6 +19,7 @@ package util import ( "bytes" "fmt" + "io" "math/rand" "os" "path/filepath" @@ -244,8 +245,8 @@ func checkFileSysStatus() { } } -func IsCloudDrivePath(absPath string) bool { - absPathLower := strings.ToLower(absPath) +func IsCloudDrivePath(workspaceAbsPath string) bool { + absPathLower := strings.ToLower(workspaceAbsPath) if isICloudPath(absPathLower) { return true } @@ -254,21 +255,23 @@ func IsCloudDrivePath(absPath string) bool { strings.Contains(absPathLower, "google drive") || strings.Contains(absPathLower, "pcloud") } -func isICloudPath(absPath string) bool { +func isICloudPath(workspaceAbsPath string) (ret bool) { if !gulu.OS.IsDarwin() { return false } // macOS 端对工作空间放置在 iCloud 路径下做检查 https://github.com/siyuan-note/siyuan/issues/7747 - iCloudRoot := filepath.Join(HomeDir, "Library", "Mobile Documents") - err := WalkWithSymlinks(iCloudRoot, func(path string, info os.FileInfo, err error) error { - logging.LogInfof("path: %s", path) + WalkWithSymlinks(iCloudRoot, func(path string, info os.FileInfo, err error) error { + if !info.IsDir() { + return nil + } + + if strings.HasPrefix(workspaceAbsPath, strings.ToLower(path)) { + ret = true + return io.EOF + } return nil }) - if nil != err { - logging.LogErrorf("walk iCloud dir [%s] failed: %s", iCloudRoot, err) - } - - return false + return }