forked from electron/electron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-symlinks.js
42 lines (36 loc) · 1.05 KB
/
check-symlinks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const fs = require('fs');
const path = require('path');
const utils = require('./lib/utils');
if (process.platform !== 'darwin') {
console.log('Not checking symlinks on non-darwin platform');
process.exit(0);
}
const appPath = path.resolve(__dirname, '..', '..', 'out', utils.getOutDir(), 'Electron.app');
const visited = new Set();
const traverse = (p) => {
if (visited.has(p)) return;
visited.add(p);
if (!fs.statSync(p).isDirectory()) return;
for (const child of fs.readdirSync(p)) {
const childPath = path.resolve(p, child);
let realPath;
try {
realPath = fs.realpathSync(childPath);
} catch (err) {
if (err.path) {
console.error('Detected an invalid symlink');
console.error('Source:', childPath);
let link = fs.readlinkSync(childPath);
if (!link.startsWith('.')) {
link = `../${link}`;
}
console.error('Target:', path.resolve(childPath, link));
process.exit(1);
} else {
throw err;
}
}
traverse(realPath);
}
};
traverse(appPath);