Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Await finish of filestream so file is created for node16
  • Loading branch information
fhammerl committed Dec 14, 2022
commit b9de68a590daf37c6747e38d3cb4f1dd2cfb791c
12 changes: 10 additions & 2 deletions packages/artifact/src/internal/download-http-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ export class DownloadHttpClient {
fileDownloadPath: string
): Promise<void> => {
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)
destinationStream = fs.createWriteStream(fileDownloadPath)
}
Expand Down Expand Up @@ -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
isThrottledStatusCode(response.message.statusCode)
? await backOff(
tryGetRetryAfterValueTimeInMilliseconds(response.message.headers)
)
tryGetRetryAfterValueTimeInMilliseconds(response.message.headers)
)
: await backOff()
} else {
// Some unexpected response code, fail immediately and stop the download
Expand Down
9 changes: 0 additions & 9 deletions packages/artifact/src/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,6 @@ export async function getFileSize(filePath: string): Promise<number> {
}

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)
}

Expand Down