mirror of https://github.com/actions/toolkit
Await finish of filestream so file is created for node16
parent
1d61e5fb19
commit
b9de68a590
|
@ -219,6 +219,14 @@ export class DownloadHttpClient {
|
||||||
fileDownloadPath: string
|
fileDownloadPath: string
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
destinationStream.close()
|
destinationStream.close()
|
||||||
|
// await until file is created at downloadpath
|
||||||
|
// wrap destinationStream's open event in promise
|
||||||
|
await new Promise<void>(resolve => {
|
||||||
|
destinationStream.on('close', resolve)
|
||||||
|
if (destinationStream.writableFinished) {
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
});
|
||||||
await rmFile(fileDownloadPath)
|
await rmFile(fileDownloadPath)
|
||||||
destinationStream = fs.createWriteStream(fileDownloadPath)
|
destinationStream = fs.createWriteStream(fileDownloadPath)
|
||||||
}
|
}
|
||||||
|
@ -273,8 +281,8 @@ export class DownloadHttpClient {
|
||||||
// if a throttled status code is received, try to get the retryAfter header value, else differ to standard exponential backoff
|
// if a throttled status code is received, try to get the retryAfter header value, else differ to standard exponential backoff
|
||||||
isThrottledStatusCode(response.message.statusCode)
|
isThrottledStatusCode(response.message.statusCode)
|
||||||
? await backOff(
|
? await backOff(
|
||||||
tryGetRetryAfterValueTimeInMilliseconds(response.message.headers)
|
tryGetRetryAfterValueTimeInMilliseconds(response.message.headers)
|
||||||
)
|
)
|
||||||
: await backOff()
|
: await backOff()
|
||||||
} else {
|
} else {
|
||||||
// Some unexpected response code, fail immediately and stop the download
|
// Some unexpected response code, fail immediately and stop the download
|
||||||
|
|
|
@ -270,15 +270,6 @@ export async function getFileSize(filePath: string): Promise<number> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function rmFile(filePath: string): Promise<void> {
|
export async function rmFile(filePath: string): Promise<void> {
|
||||||
// TODO: find actual fix
|
|
||||||
// node 16 `CreateWriteStream` no longer creates a file
|
|
||||||
// download-http-client.ts#L151 no longer creates a file and we fail here
|
|
||||||
try {
|
|
||||||
await fs.stat(filePath)
|
|
||||||
} catch (e) {
|
|
||||||
// File does not exist
|
|
||||||
return
|
|
||||||
}
|
|
||||||
await fs.unlink(filePath)
|
await fs.unlink(filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue