main.ts: installer use filehandle, make sure we fsync it before close

This commit is contained in:
Cole Mickens 2023-10-23 10:32:50 +02:00
parent 4e0fccbf7c
commit 663467bee8
No known key found for this signature in database
3 changed files with 12 additions and 11 deletions

9
dist/index.js vendored
View file

@ -329,13 +329,14 @@ class NixInstallerAction {
}
const tempdir = await (0,node_fs_promises__WEBPACK_IMPORTED_MODULE_2__.mkdtemp)((0,node_path__WEBPACK_IMPORTED_MODULE_5__.join)((0,node_os__WEBPACK_IMPORTED_MODULE_6__.tmpdir)(), "nix-installer-"));
const tempfile = (0,node_path__WEBPACK_IMPORTED_MODULE_5__.join)(tempdir, `nix-installer-${this.platform}`);
if (!response.ok) {
throw new Error(`unexpected response ${response.statusText}`);
}
if (response.body !== null) {
const fileStream = node_fs__WEBPACK_IMPORTED_MODULE_8___default().createWriteStream(tempfile);
const handle = await (0,node_fs_promises__WEBPACK_IMPORTED_MODULE_2__.open)(tempfile, "w");
const fileStream = handle.createWriteStream({ autoClose: false });
const fileStreamWeb = node_stream__WEBPACK_IMPORTED_MODULE_7___default().Writable.toWeb(fileStream);
await response.body.pipeTo(fileStreamWeb);
// fileStreamWeb is auto-closed by pipeTo, confirmed
fileStream.close();
await handle.sync();
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`Downloaded \`nix-installer\` to \`${tempfile}\``);
}
else {

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
import * as actions_core from "@actions/core";
import * as github from "@actions/github";
import { mkdtemp, chmod, access, writeFile } from "node:fs/promises";
import { mkdtemp, chmod, access, writeFile, open } from "node:fs/promises";
import { spawn } from "node:child_process";
import { randomUUID } from "node:crypto";
import { join } from "node:path";
@ -429,14 +429,14 @@ class NixInstallerAction {
const tempdir = await mkdtemp(join(tmpdir(), "nix-installer-"));
const tempfile = join(tempdir, `nix-installer-${this.platform}`);
if (!response.ok) {
throw new Error(`unexpected response ${response.statusText}`);
}
if (response.body !== null) {
const fileStream = fs.createWriteStream(tempfile);
const handle = await open(tempfile, "w");
const fileStream = handle.createWriteStream({ autoClose: false });
const fileStreamWeb = stream.Writable.toWeb(fileStream);
await response.body.pipeTo(fileStreamWeb);
// fileStreamWeb is auto-closed by pipeTo, confirmed
fileStream.close();
await handle.sync();
actions_core.info(`Downloaded \`nix-installer\` to \`${tempfile}\``);
} else {