diff --git a/server/container-baby.ts b/server/container-baby.ts index 24e30c9..67f286c 100644 --- a/server/container-baby.ts +++ b/server/container-baby.ts @@ -1,5 +1,5 @@ import { execFile as _execFile } from "node:child_process"; -import { access, mkdir, open, writeFile } from "node:fs/promises"; +import { access, mkdir, open, rename, writeFile } from "node:fs/promises"; import { join } from "node:path"; import { tar2squashfs } from "./tar2squashfs.js"; import { subtle } from "node:crypto"; @@ -76,6 +76,7 @@ async function saveSquashfs( if (!p) { p = (async () => { const output = join(cacheDir, key); + const progressFile = output + ".downloading"; try { await access(output); // ya está cacheado @@ -92,7 +93,7 @@ async function saveSquashfs( const res = await getBlob(image, layer.digest); return res.body!; }); - await tar2squashfs(layerStreams, output, [ + await tar2squashfs(layerStreams, progressFile, [ { content: configJson, headers: { @@ -103,6 +104,7 @@ async function saveSquashfs( }, }, ]); + await rename(progressFile, output); } return output; })();