(dir: string)
| 66 | } |
| 67 | |
| 68 | function validateSocketDir(dir: string): void { |
| 69 | const linkStat = lstatSync(dir); |
| 70 | if (linkStat.isSymbolicLink()) { |
| 71 | throw new Error(`Daemon socket directory cannot be a symlink: ${dir}`); |
| 72 | } |
| 73 | |
| 74 | const stat = statSync(dir); |
| 75 | if (!stat.isDirectory()) { |
| 76 | throw new Error(`Daemon socket path parent is not a directory: ${dir}`); |
| 77 | } |
| 78 | |
| 79 | const uid = process.getuid?.(); |
| 80 | if (uid !== undefined && stat.uid !== uid) { |
| 81 | throw new Error(`Daemon socket directory is not owned by the current user: ${dir}`); |
| 82 | } |
| 83 | |
| 84 | if ((stat.mode & 0o077) !== 0) { |
| 85 | chmodSync(dir, 0o700); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | export function ensureSocketDir(socketPath: string): void { |
| 90 | const dir = dirname(socketPath); |
no test coverage detected