mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-24 02:20:13 +01:00
🎨 Clean code Improve iCloud path checking https://github.com/siyuan-note/siyuan/pull/9066
This commit is contained in:
parent
b0b7b6f17a
commit
6f42ac392e
1 changed files with 15 additions and 11 deletions
|
|
@ -421,45 +421,49 @@
|
|||
|
||||
// macOS 端对工作空间放置在 iCloud 路径下做检查 https://github.com/siyuan-note/siyuan/issues/7747
|
||||
const path = require('path')
|
||||
const homePath = decodeURIComponent(getSearch('home'))
|
||||
const homePath = decodeURIComponent(getSearch('home'))
|
||||
const absPathLower = absPath.toLowerCase()
|
||||
const iCloudRoot = path.join(homePath, 'Library', 'Mobile Documents')
|
||||
if(!simpleCheckIcloudPath(absPath, homePath)){
|
||||
//简单判断无法通过则复杂验证
|
||||
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)=>{
|
||||
|
||||
// 简单判断 iCloud 同步目录
|
||||
// 不允许 为桌面 文档 和 iCloud 文件夹 和软链接
|
||||
const simpleCheckIcloudPath = (absPath, homePath) => {
|
||||
const fs = require('fs')
|
||||
let stat = fs.lstatSync(absPath)
|
||||
if(stat.isSymbolicLink()){
|
||||
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())){
|
||||
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
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
const walk = (dir, files = []) => {
|
||||
let dirFiles;
|
||||
const fs = require('fs')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue