Skip to content

Commit 3b5dafb

Browse files
authored
chore(hadron-build): fix download destination (#3337)
fix(hadron-build): fix download destination download function second argument is a destination directory, not a destination file. Instead of using it, let's pipe to file instead.
1 parent dc756fd commit 3b5dafb

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/hadron-build/commands/upload.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ const root = path.resolve(__dirname, '..', '..', '..');
2828

2929
async function checkAssetsExist(paths) {
3030
await Promise.all(
31-
paths.map((assetPath) => {
32-
return fs.stat(assetPath);
31+
paths.map(async(assetPath) => {
32+
const stats = await fs.stat(assetPath);
33+
if (!stats.isFile()) {
34+
throw new TypeError(`Not a file at path ${assetPath}`);
35+
}
3336
})
3437
);
3538
return true;

packages/hadron-build/lib/download-center.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable valid-jsdoc */
22
const fs = require('fs');
3+
const path = require('path');
34
const { DownloadCenter } = require('@mongodb-js/dl-center');
45
const download = require('download');
56

@@ -50,15 +51,21 @@ const uploadManifest = async(manifest) => {
5051
return dlCenter.uploadConfig(MANIFEST_OBJECT_KEY, manifest);
5152
};
5253

53-
const downloadAssetFromEvergreen = async({ name, path: dest }) => {
54-
requireEnvironmentVariables([
55-
'EVERGREEN_BUCKET_NAME',
56-
'EVERGREEN_BUCKET_KEY_PREFIX'
57-
]);
58-
const bucket = process.env.EVERGREEN_BUCKET_NAME;
59-
const key = `${process.env.EVERGREEN_BUCKET_KEY_PREFIX}/${name}`;
60-
const url = `https://${bucket}.s3.amazonaws.com/${key}`;
61-
return await download(url, dest);
54+
const downloadAssetFromEvergreen = ({ name, path: dest }) => {
55+
return new Promise(async(resolve, reject) => {
56+
requireEnvironmentVariables([
57+
'EVERGREEN_BUCKET_NAME',
58+
'EVERGREEN_BUCKET_KEY_PREFIX'
59+
]);
60+
const bucket = process.env.EVERGREEN_BUCKET_NAME;
61+
const key = `${process.env.EVERGREEN_BUCKET_KEY_PREFIX}/${name}`;
62+
const url = `https://${bucket}.s3.amazonaws.com/${key}`;
63+
const stream = download(url);
64+
await fs.promises.mkdir(path.dirname(dest), { recursive: true });
65+
stream.pipe(fs.createWriteStream(dest));
66+
stream.on('end', resolve);
67+
stream.on('error', reject);
68+
});
6269
};
6370

6471
module.exports = {

0 commit comments

Comments
 (0)