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 36ccc35
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
6 changes: 5 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,13 @@ class NixInstallerAction {
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, (node_fs__WEBPACK_IMPORTED_MODULE_8___default().constants.O_CREAT) | (node_fs__WEBPACK_IMPORTED_MODULE_8___default().constants.O_TRUNC) | (node_fs__WEBPACK_IMPORTED_MODULE_8___default().constants.O_DSYNC));
const fileStream = handle.createWriteStream();
const fileStreamWeb = node_stream__WEBPACK_IMPORTED_MODULE_7___default().Writable.toWeb(fileStream);
await response.body.pipeTo(fileStreamWeb);
await handle.sync();
fileStream.close();
await handle.close();
_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.

11 changes: 9 additions & 2 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 @@ -434,9 +434,16 @@ class NixInstallerAction {
}

if (response.body !== null) {
const fileStream = fs.createWriteStream(tempfile);
const handle = await open(
tempfile,
fs.constants.O_CREAT | fs.constants.O_TRUNC | fs.constants.O_DSYNC,
);
const fileStream = handle.createWriteStream();
const fileStreamWeb = stream.Writable.toWeb(fileStream);
await response.body.pipeTo(fileStreamWeb);
await handle.sync();
fileStream.close();
await handle.close();

actions_core.info(`Downloaded \`nix-installer\` to \`${tempfile}\``);
} else {
Expand Down

0 comments on commit 36ccc35

Please sign in to comment.