Skip to content

Commit

Permalink
main.ts: installer use filehandle, make sure we fsync it before close
Browse files Browse the repository at this point in the history
  • Loading branch information
colemickens committed Oct 24, 2023
1 parent 4e0fccb commit 663467b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
9 changes: 5 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 663467b

Please sign in to comment.