(path: string)
| 621 | |
| 622 | // Exported for testing |
| 623 | export async function removeDirectoryIfEmpty(path: string): Promise<void> { |
| 624 | // rmdir alone handles all cases: ENOTDIR if path is a file, ENOTEMPTY if |
| 625 | // directory is non-empty, ENOENT if missing. No need to stat+readdir first. |
| 626 | try { |
| 627 | await rmdir(path) |
| 628 | logForDebugging(`Removed empty directory at ${path}`) |
| 629 | } catch (error) { |
| 630 | const code = getErrnoCode(error) |
| 631 | // Expected cases (not-a-dir, missing, not-empty) — silently skip. |
| 632 | // ENOTDIR is the normal path: executablePath is typically a symlink. |
| 633 | if (code !== 'ENOTDIR' && code !== 'ENOENT' && code !== 'ENOTEMPTY') { |
| 634 | logForDebugging(`Could not remove directory at ${path}: ${error}`) |
| 635 | } |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | async function updateSymlink( |
| 640 | symlinkPath: string, |
no test coverage detected