Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve iCloud path checking #9066

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions app/electron/init.html
Original file line number Diff line number Diff line change
Expand Up @@ -421,17 +421,45 @@ <h2>SiYuan</h2>

// 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(!simpleCheckIcloudPath(absPath, homePath)){
//简单判断无法通过则复杂验证
const allFiles = walk(iCloudRoot)
for (const file of allFiles) {
if (-1 < absPathLower.indexOf(file.toLowerCase())) {
return true
}
}
}
}
return false
}
//简单判断Icloud同步目录
//不允许 为桌面 文档 和 icloud 文件夹 和软链接
const simpleCheckIcloudPath =(absPath, homePath)=>{
const fs = require('fs')
let stat = fs.lstatSync(absPath)
if(stat.isSymbolicLink()){
return false
}
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 = []) => {
let dirFiles;
const fs = require('fs')
Expand All @@ -440,7 +468,6 @@ <h2>SiYuan</h2>
console.log("dir [" + dir + "] not exists")
return files
}

dirFiles = fs.readdirSync(dir)
} catch (e) {
console.error("read dir [" + dir + "] failed: ", e)
Expand All @@ -459,9 +486,8 @@ <h2>SiYuan</h2>
if (files.includes(dir + path.sep + f)) {
continue
}
walk(dir + path.sep + f, files)
} else {
files.push(dir + path.sep + f)
walk(dir + path.sep + f, files)
}
}
return files
Expand Down