Skip to content

Commit 74664b2

Browse files
committed
fix: racing condition of binary access
1 parent 4486dcc commit 74664b2

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

src/install.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ export async function install_linux(to: string, version = "latest"): Promise<str
5757
}
5858

5959
await download(resolve_base(version) + file, to);
60-
await new Promise((r) => setTimeout(r, 100));
6160
fs.chmodSync(to, "755");
6261
return to;
6362
}
@@ -105,17 +104,17 @@ function download(url: string, to: string, redirect = 0): Promise<string> {
105104
const file = fs.createWriteStream(to);
106105
const request = https.get(url, (res) => {
107106
if (res.statusCode === 302 && res.headers.location !== undefined) {
107+
const redirection = res.headers.location;
108108
done = false;
109-
file.close();
110-
resolve(download(res.headers.location, to, redirect + 1));
109+
file.close(() => resolve(download(redirection, to, redirect + 1)));
111110
return;
112111
}
113112
res.pipe(file);
114113
});
115114

116115
file.on("finish", () => {
117116
if (done) {
118-
resolve(to);
117+
file.close(() => resolve(to));
119118
}
120119
});
121120

0 commit comments

Comments
 (0)