Files
AirCoding/packages/core/test/fixture/tmpdir.ts
airlongdian c4f9fe109e fix: logo 右半部分从 CODING 改为 CODE
去掉难以正确渲染的 N 和 G 字母,右半部分简化为 CODE(4 字母),
与左半部分 AIR 组合为 AIR CODE。
2026-06-14 09:54:53 +08:00

26 lines
687 B
TypeScript

import fs from "fs/promises"
import { tmpdir as osTmpdir } from "os"
import path from "path"
export const tmpdir = async () => {
const dir = await fs.realpath(await fs.mkdtemp(path.join(osTmpdir(), "opencode-core-test-")))
return {
path: dir,
async [Symbol.asyncDispose]() {
await remove(dir)
},
}
}
async function remove(dir: string, retries = 30): Promise<void> {
try {
await fs.rm(dir, { recursive: true, force: true })
} catch (error) {
if (retries === 0 || !error || typeof error !== "object" || !("code" in error) || error.code !== "EBUSY")
throw error
Bun.gc(true)
await Bun.sleep(100)
return remove(dir, retries - 1)
}
}