MCPcopy
hub / github.com/codeaashu/claude-code / removeDirectoryIfEmpty

Function removeDirectoryIfEmpty

src/utils/nativeInstaller/installer.ts:623–637  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

621
622// Exported for testing
623export 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
639async function updateSymlink(
640 symlinkPath: string,

Callers 1

performVersionUpdateFunction · 0.85

Calls 3

rmdirFunction · 0.85
logForDebuggingFunction · 0.85
getErrnoCodeFunction · 0.85

Tested by

no test coverage detected