From 6a34d7e70661b7a1009164bf543e08d1a59ae17e Mon Sep 17 00:00:00 2001 From: Im-Beast Date: Sun, 29 Dec 2024 14:28:12 +0100 Subject: tests: don't try to extract file if out already exists --- tests/utils.ts | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'tests/utils.ts') diff --git a/tests/utils.ts b/tests/utils.ts index 348ded9..86501a8 100755 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -50,6 +50,18 @@ export function loadDylib(coin: Coin, version: MoneroCVersion) { } } +async function exists(path: string): Promise { + try { + await Deno.stat(path); + return true; + } catch (error) { + if (error instanceof Deno.errors.NotFound) { + return false; + } + throw error; + } +} + export async function extract(path: string, out: string) { const outDir = out.endsWith("/") ? out : dirname(out); await Deno.mkdir(outDir, { recursive: true }); @@ -169,19 +181,25 @@ export async function prepareMoneroC(coin: Coin, version: MoneroCVersion) { const releaseDylibName = dylibName.slice(`${coin}_`.length); if (version === "next") { - await extract( - `./release/${coin}/${releaseDylibName}.xz`, - `./tests/dependencies/libs/next/${moneroTsDylibName}`, - ); + const outFileDir = `./tests/dependencies/libs/${version}/${moneroTsDylibName}`; + + if (await exists(outFileDir)) { + return; + } + + await extract(`./release/${coin}/${releaseDylibName}.xz`, outFileDir); } else { + const outFileDir = `./tests/dependencies/libs/${version}/${moneroTsDylibName}`; + + if (await exists(outFileDir)) { + return; + } + const downloadInfo = dylibInfos[coin].find((info) => info.outDir?.endsWith(version)); if (downloadInfo) { await downloadDependencies(downloadInfo); } - await extract( - `./tests/dependencies/libs/${version}/${dylibName}.xz`, - `./tests/dependencies/libs/${version}/${moneroTsDylibName}`, - ); + await extract(`./tests/dependencies/libs/${version}/${dylibName}.xz`, outFileDir); } } -- cgit v1.2.3