Remove unused readdir import, simplify rmdir loop
This commit is contained in:
parent
385673f420
commit
e8318f68b0
|
|
@ -1,6 +1,6 @@
|
||||||
import { basename, dirname, join } from "path"
|
import { basename, dirname, join } from "path"
|
||||||
import { homedir } from "os"
|
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 { $ } from "bun"
|
||||||
import * as git from "../git.ts"
|
import * as git from "../git.ts"
|
||||||
import * as vm from "../vm.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
|
// Walk up from the symlink's parent, removing empty dirs, stopping at .sandlot/ itself
|
||||||
let dir = dirname(symlinkPath)
|
let dir = dirname(symlinkPath)
|
||||||
while (dir !== sandlotDir) {
|
while (dir !== sandlotDir) {
|
||||||
const entries = await readdir(dir).catch(() => null)
|
const ok = await rmdir(dir).then(() => true, () => false)
|
||||||
if (!entries || entries.length > 0) break
|
if (!ok) break
|
||||||
await rmdir(dir).catch(() => {})
|
|
||||||
dir = dirname(dir)
|
dir = dirname(dir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user