Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

symlinks.ts

26 lines1.0 KB

1// @effect-diagnostics nodeBuiltinImport:off - one synchronous probe at module load, outside any Effect runtime.
2import * as NodeFS from "node:fs";
3import * as NodeOS from "node:os";
4import * as NodePath from "node:path";
5​
6/**
7 * Windows refuses without Developer Mode or elevation, so tests that plant a
8 * symlink to prove containment or escape detection should
9 * `skipIf(!symlinksSupported)` rather than fail at setup.
10 */
11export const symlinksSupported: boolean = (() => {
12 let directory: string | undefined;
13 try {
14 directory = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-symlink-probe-"));
15 NodeFS.symlinkSync(NodePath.join(directory, "target"), NodePath.join(directory, "link"));
16 return true;
17 } catch {
18 return false;
19 } finally {
20 // Cleanup must not decide the answer: a transient EPERM/EBUSY on the
21 // probe directory would otherwise throw out of module initialisation.
22 try {
23 if (directory !== undefined) NodeFS.rmSync(directory, { recursive: true, force: true });
24 } catch {}
25 }
26})();