(path: string)
| 609 | |
| 610 | // Exported for testing |
| 611 | export async function removeDirectoryIfEmpty(path: string): Promise<void> { |
| 612 | // rmdir alone handles all cases: ENOTDIR if path is a file, ENOTEMPTY if |
| 613 | // directory is non-empty, ENOENT if missing. No need to stat+readdir first. |
| 614 | try { |
| 615 | await rmdir(path) |
| 616 | logForDebugging(`Removed empty directory at ${path}`) |
| 617 | } catch (error) { |
| 618 | const code = getErrnoCode(error) |
| 619 | // Expected cases (not-a-dir, missing, not-empty) — silently skip. |
| 620 | // ENOTDIR is the normal path: executablePath is typically a symlink. |
| 621 | if (code !== 'ENOTDIR' && code !== 'ENOENT' && code !== 'ENOTEMPTY') { |
| 622 | logForDebugging(`Could not remove directory at ${path}: ${error}`) |
| 623 | } |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | async function updateSymlink( |
| 628 | symlinkPath: string, |
no test coverage detected