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 1/2] =?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 From df92b5e1639a8ee10bb02b3529b5eff48bf132f5 Mon Sep 17 00:00:00 2001 From: misterzhang <1345260334@qq.com> Date: Tue, 29 Aug 2023 20:54:42 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E6=8F=90=E4=BA=A4=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?icloud=E5=88=A4=E6=96=AD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.删除无用的else块 2.完善simpleCheckIcloudPath方法 添加 桌面 和文档的路径判断 --- app/electron/init.html | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/app/electron/init.html b/app/electron/init.html index 17489bc01e6..b689b6a8fd6 100644 --- a/app/electron/init.html +++ b/app/electron/init.html @@ -424,8 +424,7 @@

SiYuan

const homePath = decodeURIComponent(getSearch('home')) const absPathLower = absPath.toLowerCase() const iCloudRoot = path.join(homePath, 'Library', 'Mobile Documents') - //进行简单判断文件路径 - if(!simpleCheckPath(absPath, iCloudRoot)){ + if(!simpleCheckIcloudPath(absPath, homePath)){ //简单判断无法通过则复杂验证 const allFiles = walk(iCloudRoot) for (const file of allFiles) { @@ -436,15 +435,29 @@

SiYuan

} return false } - const simpleCheckPath =(path, iCloudRoot)=>{ + //简单判断Icloud同步目录 + //不允许 为桌面 文档 和 icloud 文件夹 和软链接 + const simpleCheckIcloudPath =(absPath, homePath)=>{ const fs = require('fs') - let stat = fs.lstatSync(path) + let stat = fs.lstatSync(absPath) if(stat.isSymbolicLink()){ - // 不允许目标路径是软链 或者硬链接 return false } - const absPathLower = path.toLowerCase() - return !(-1 < absPathLower.indexOf(iCloudRoot.toLowerCase())) + const path = require('path') + const absPathLower = absPath.toLowerCase() + const iCloudRoot = path.join(homePath, 'Library', 'Mobile Documents') + if(absPathLower.startsWith(iCloudRoot.toLowerCase())){ + return false + } + const documentsRoot = path.join(homePath, 'Documents') + if (absPathLower.startsWith(documentsRoot.toLowerCase())) { + return false + } + const desktopRoot = path.join(homePath, 'Desktop') + if (absPathLower.startsWith(desktopRoot.toLowerCase())) { + return false + } + return true } const walk = (dir, files = []) => { @@ -475,9 +488,6 @@

SiYuan

} files.push(dir + path.sep + f) walk(dir + path.sep + f, files) - } else { - //不在添加文件到过滤路径 最小细粒度为目录 - //files.push(dir + path.sep + f) } } return files