* Rename the running (locked) node.exe out of `dir` so the rest of the tree * deletes cleanly — Windows allows renaming a mapped image, just not deleting * it. Returns the leftover path, or null when nothing needed moving.
(dir: string, deps: RemoveBinaryDeps)
| 247 | * it. Returns the leftover path, or null when nothing needed moving. |
| 248 | */ |
| 249 | function moveLockedExeAside(dir: string, deps: RemoveBinaryDeps): string | null { |
| 250 | if (deps.platform !== 'win32') return null; |
| 251 | const P = pathFor(deps.platform); |
| 252 | const resolvedDir = P.resolve(dir) + P.sep; |
| 253 | if (!P.resolve(deps.execPath).startsWith(resolvedDir)) return null; |
| 254 | const leftover = P.join(P.dirname(P.resolve(dir)), `codegraph-old-node-${process.pid}.exe`); |
| 255 | try { |
| 256 | deps.rename(deps.execPath, leftover); |
| 257 | return leftover; |
| 258 | } catch { |
| 259 | return null; // rename failed too — the rm error will surface the dir |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | export function executeBinaryRemoval( |
| 264 | plan: BinaryRemovalPlan, |
no test coverage detected