(data)
| 30 | } |
| 31 | |
| 32 | function writeSettings(data) { |
| 33 | const dir = getSettingsDir(); |
| 34 | const file = getSettingsFile(); |
| 35 | if (!fs.existsSync(dir)) { |
| 36 | fs.mkdirSync(dir, { recursive: true }); |
| 37 | } |
| 38 | const current = readSettings(); |
| 39 | const merged = { ...current, ...data }; |
| 40 | // NOTE(windows): mode 0o600 is silently ignored on Windows. The settings |
| 41 | // file (which may contain proxy credentials) will NOT be owner-read-only. |
| 42 | // Only Windows user-profile directory ACLs provide isolation. The chmodSync |
| 43 | // call below is also a no-op on Windows but is retained for Unix correctness. |
| 44 | fs.writeFileSync(file, JSON.stringify(merged, null, 2), { encoding: 'utf8', mode: 0o600 }); |
| 45 | // mode: 0o600 only applies on creation; explicitly chmod to tighten pre-existing files |
| 46 | try { fs.chmodSync(file, 0o600); } catch { /* best-effort; no-op on Windows */ } |
| 47 | return merged; |
| 48 | } |
| 49 | |
| 50 | function clearSettings(opts = {}) { |
| 51 | try { |
no test coverage detected