diff --git a/src/commands/helpers.ts b/src/commands/helpers.ts index fbb45fa..922ca75 100644 --- a/src/commands/helpers.ts +++ b/src/commands/helpers.ts @@ -1,6 +1,6 @@ import { basename, dirname, join } from "path" import { homedir } from "os" -import { mkdir, readdir, rmdir, symlink, unlink } from "fs/promises" +import { mkdir, rmdir, symlink, unlink } from "fs/promises" import { $ } from "bun" import * as git from "../git.ts" import * as vm from "../vm.ts" @@ -18,9 +18,8 @@ export async function unlinkSessionSymlink(root: string, branch: string): Promis // Walk up from the symlink's parent, removing empty dirs, stopping at .sandlot/ itself let dir = dirname(symlinkPath) while (dir !== sandlotDir) { - const entries = await readdir(dir).catch(() => null) - if (!entries || entries.length > 0) break - await rmdir(dir).catch(() => {}) + const ok = await rmdir(dir).then(() => true, () => false) + if (!ok) break dir = dirname(dir) } }