From 0837fc0fa5b219f1197f8662961511337f99697e Mon Sep 17 00:00:00 2001
From: misterzhang <1345260334@qq.com>
Date: Tue, 29 Aug 2023 11:31:57 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20icloud=E7=9B=AE=E5=BD=95=E5=88=A4?=
=?UTF-8?q?=E6=96=AD=E8=8C=83=E5=9B=B4=E5=A4=AA=E5=B9=BF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
icloud 目录匹配包含导致全局无法正常使用
---
app/electron/init.html | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/app/electron/init.html b/app/electron/init.html
index ba010adf47b..17489bc01e6 100644
--- a/app/electron/init.html
+++ b/app/electron/init.html
@@ -421,17 +421,32 @@
SiYuan
// macOS 端对工作空间放置在 iCloud 路径下做检查 https://github.com/siyuan-note/siyuan/issues/7747
const path = require('path')
- const iCloudRoot = path.join(decodeURIComponent(getSearch('home')), 'Library', 'Mobile Documents')
- const allFiles = walk(iCloudRoot)
+ const homePath = decodeURIComponent(getSearch('home'))
const absPathLower = absPath.toLowerCase()
- for (const file of allFiles) {
- if (-1 < absPathLower.indexOf(file.toLowerCase())) {
- return true
+ const iCloudRoot = path.join(homePath, 'Library', 'Mobile Documents')
+ //进行简单判断文件路径
+ if(!simpleCheckPath(absPath, iCloudRoot)){
+ //简单判断无法通过则复杂验证
+ const allFiles = walk(iCloudRoot)
+ for (const file of allFiles) {
+ if (-1 < absPathLower.indexOf(file.toLowerCase())) {
+ return true
+ }
}
- }
+ }
return false
}
+ const simpleCheckPath =(path, iCloudRoot)=>{
+ const fs = require('fs')
+ let stat = fs.lstatSync(path)
+ if(stat.isSymbolicLink()){
+ // 不允许目标路径是软链 或者硬链接
+ return false
+ }
+ const absPathLower = path.toLowerCase()
+ return !(-1 < absPathLower.indexOf(iCloudRoot.toLowerCase()))
+ }
const walk = (dir, files = []) => {
let dirFiles;
const fs = require('fs')
@@ -440,7 +455,6 @@ SiYuan
console.log("dir [" + dir + "] not exists")
return files
}
-
dirFiles = fs.readdirSync(dir)
} catch (e) {
console.error("read dir [" + dir + "] failed: ", e)
@@ -459,9 +473,11 @@ SiYuan
if (files.includes(dir + path.sep + f)) {
continue
}
+ files.push(dir + path.sep + f)
walk(dir + path.sep + f, files)
} else {
- files.push(dir + path.sep + f)
+ //不在添加文件到过滤路径 最小细粒度为目录
+ //files.push(dir + path.sep + f)
}
}
return files