🎨 macOS 端对工作空间放置在 iCloud 路径下做检查 https://github.com/siyuan-note/siyuan/issues/7747

This commit is contained in:
Liang Ding 2023-03-23 09:18:54 +08:00
parent 3f9d32d6ff
commit 0323b89e95
No known key found for this signature in database
GPG key ID: 136F30F901A2231D

View file

@ -19,6 +19,7 @@ package util
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io"
"math/rand" "math/rand"
"os" "os"
"path/filepath" "path/filepath"
@ -244,8 +245,8 @@ func checkFileSysStatus() {
} }
} }
func IsCloudDrivePath(absPath string) bool { func IsCloudDrivePath(workspaceAbsPath string) bool {
absPathLower := strings.ToLower(absPath) absPathLower := strings.ToLower(workspaceAbsPath)
if isICloudPath(absPathLower) { if isICloudPath(absPathLower) {
return true return true
} }
@ -254,21 +255,23 @@ func IsCloudDrivePath(absPath string) bool {
strings.Contains(absPathLower, "google drive") || strings.Contains(absPathLower, "pcloud") strings.Contains(absPathLower, "google drive") || strings.Contains(absPathLower, "pcloud")
} }
func isICloudPath(absPath string) bool { func isICloudPath(workspaceAbsPath string) (ret bool) {
if !gulu.OS.IsDarwin() { if !gulu.OS.IsDarwin() {
return false return false
} }
// macOS 端对工作空间放置在 iCloud 路径下做检查 https://github.com/siyuan-note/siyuan/issues/7747 // macOS 端对工作空间放置在 iCloud 路径下做检查 https://github.com/siyuan-note/siyuan/issues/7747
iCloudRoot := filepath.Join(HomeDir, "Library", "Mobile Documents") iCloudRoot := filepath.Join(HomeDir, "Library", "Mobile Documents")
err := WalkWithSymlinks(iCloudRoot, func(path string, info os.FileInfo, err error) error { WalkWithSymlinks(iCloudRoot, func(path string, info os.FileInfo, err error) error {
logging.LogInfof("path: %s", path) if !info.IsDir() {
return nil
}
if strings.HasPrefix(workspaceAbsPath, strings.ToLower(path)) {
ret = true
return io.EOF
}
return nil return nil
}) })
if nil != err { return
logging.LogErrorf("walk iCloud dir [%s] failed: %s", iCloudRoot, err)
}
return false
} }