Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 9da8020

Browse files
authored
Merge pull request #35 from cantremember/issue_33_osx_win32_archive_naming
Fix v3.6.x (and above) download issues for Mac OSX, Windows
2 parents e0d97db + 65942ce commit 9da8020

File tree

3 files changed

+733
-7
lines changed

3 files changed

+733
-7
lines changed

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"bin": "built/mongodb-download-cli.js",
77
"types": "built/mongodb-download.d.ts",
88
"scripts": {
9+
"build": "tsc",
910
"test": "mocha"
1011
},
1112
"repository": {
@@ -22,6 +23,7 @@
2223
"url": "https://github.com/winfinit/mongodb-download/issues"
2324
},
2425
"dependencies": {
26+
"semver": "^5.6.0",
2527
"yargs": "^3.26.0",
2628
"debug": "^2.2.0",
2729
"getos": "^2.7.0",
@@ -34,7 +36,9 @@
3436
"devDependencies": {
3537
"@types/node": "^6.0.70",
3638
"chai": "^3.5.0",
37-
"mocha": "^3.2.0"
39+
"mocha": "^3.2.0",
40+
"rewire": "^4.0.1",
41+
"typescript": "^3.1.3"
3842
},
3943
"homepage": "https://github.com/winfinit/mongodb-download#readme"
4044
}

src/mongodb-download.ts

+25-6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ const path: any = require('path');
55
const Debug: any = require('debug');
66
const getos: any = require('getos');
77
const url: any = require('url');
8+
const semver: any = require('semver');
89
const decompress: any = require('decompress');
910
const request: any = require('request-promise');
1011
const md5File: any = require('md5-file');
1112

12-
const DOWNLOAD_URI: string = "https://downloads.mongodb.org";
13+
const DOWNLOAD_URI: string = "https://fastdl.mongodb.org";
1314
const MONGODB_VERSION: string = "latest";
1415

1516
export interface IMongoDBDownloadOptions {
@@ -273,7 +274,7 @@ export class MongoDBDownload {
273274
this.getDownloadURIMD5().then((md5URL) => {
274275
request(md5URL).then((signatureContent: string) => {
275276
this.debug(`getDownloadMD5Hash content: ${signatureContent}`);
276-
let signatureMatch: string[] = signatureContent.match(/(.*?)\s/);
277+
let signatureMatch: string[] = signatureContent.match(/([^\s]*)(\s*|$)/);
277278
let signature: string = signatureMatch[1];
278279
this.debug(`getDownloadMD5Hash extracted signature: ${signature}`);
279280
this.cacheMD5Hash(signature).then(() => {
@@ -426,10 +427,26 @@ export class MongoDBDownload {
426427

427428
getArchiveName(): Promise<string> {
428429
return new Promise<string>((resolve, reject) => {
429-
//var name = "mongodb-" + mongo_platform + "-" + mongo_arch;
430-
let name = "mongodb-" +
431-
this.mongoDBPlatform.getPlatform() + "-" +
432-
this.mongoDBPlatform.getArch();
430+
let platform: string = this.mongoDBPlatform.getPlatform();
431+
let arch: string = this.mongoDBPlatform.getArch();
432+
let version: string = this.getVersion();
433+
434+
switch (platform) {
435+
case 'osx':
436+
if ((version === 'latest') || semver.satisfies(version, '>=3.5')) {
437+
platform = `${platform}-ssl`;
438+
}
439+
break;
440+
case 'win32':
441+
// TODO: '2012plus' for 4.x and above
442+
if ((version === 'latest') || semver.satisfies(version, '>=3.5')) {
443+
arch = `${arch}-2008plus-ssl`;
444+
}
445+
break;
446+
default:
447+
break;
448+
}
449+
let name: string = `mongodb-${platform}-${arch}`;
433450

434451
this.mongoDBPlatform.getOSVersionString().then(osString => {
435452
osString && (name += `-${osString}`);
@@ -506,6 +523,7 @@ export class MongoDBPlatform {
506523
} else if (/debian/i.test(os.dist)) {
507524
resolve(this.getDebianVersionString(os));
508525
} else {
526+
// TODO: 'legacy', 'static'
509527
reject("");
510528
}
511529
});
@@ -551,6 +569,7 @@ export class MongoDBPlatform {
551569
} else if (/^5/.test(os.release)) {
552570
name += "55";
553571
} else {
572+
// TODO: 'rhel57'
554573
this.debug("using legacy release");
555574
}
556575
return name;

0 commit comments

Comments
 (0)