guardar en .downloading cuando todavía no se bajó

This commit is contained in:
Cat /dev/Nulo 2023-07-17 19:48:21 -03:00
parent 8cd396335a
commit e349bc7cad

View file

@ -1,5 +1,5 @@
import { execFile as _execFile } from "node:child_process"; 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 { join } from "node:path";
import { tar2squashfs } from "./tar2squashfs.js"; import { tar2squashfs } from "./tar2squashfs.js";
import { subtle } from "node:crypto"; import { subtle } from "node:crypto";
@ -76,6 +76,7 @@ async function saveSquashfs(
if (!p) { if (!p) {
p = (async () => { p = (async () => {
const output = join(cacheDir, key); const output = join(cacheDir, key);
const progressFile = output + ".downloading";
try { try {
await access(output); await access(output);
// ya está cacheado // ya está cacheado
@ -92,7 +93,7 @@ async function saveSquashfs(
const res = await getBlob(image, layer.digest); const res = await getBlob(image, layer.digest);
return res.body!; return res.body!;
}); });
await tar2squashfs(layerStreams, output, [ await tar2squashfs(layerStreams, progressFile, [
{ {
content: configJson, content: configJson,
headers: { headers: {
@ -103,6 +104,7 @@ async function saveSquashfs(
}, },
}, },
]); ]);
await rename(progressFile, output);
} }
return output; return output;
})(); })();