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

Commit c17fa8e

Browse files
author
Dan Foley
committed
Fix v3.6.x (and above) download issues for Mac OSX
#33 - 'osx' archive naming changed in v3.5 - 'win32' archive naming changed in v3.5 - not all signatures end with trailing whitespace - MongoDB site Downloads send folks to 'fastdl.mongodb.org' - added Test Suite for package/arch/version/os variants - TODOs for 'linux'; 'legacy', 'static', 'debian92', 'rhel57' - TypeScript development tooling w/ `npm run build`
1 parent 6395930 commit c17fa8e

File tree

3 files changed

+735
-7
lines changed

3 files changed

+735
-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

+27-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(() => {
@@ -427,10 +428,27 @@ export class MongoDBDownload {
427428
getArchiveName(): Promise<string> {
428429
return new Promise<string>((resolve, reject) => {
429430
//var name = "mongodb-" + mongo_platform + "-" + mongo_arch;
430-
let name = "mongodb-" +
431-
this.mongoDBPlatform.getPlatform() + "-" +
432-
this.mongoDBPlatform.getArch();
433-
431+
let platform: string = this.mongoDBPlatform.getPlatform();
432+
let arch: string = this.mongoDBPlatform.getArch();
433+
let version: string = this.getVersion();
434+
435+
switch (platform) {
436+
case 'osx':
437+
if ((version === 'latest') || semver.satisfies(version, '>=3.5')) {
438+
platform = `${platform}-ssl`;
439+
}
440+
break;
441+
case 'win32':
442+
// TODO: '2012plus' for 4.x and above
443+
if ((version === 'latest') || semver.satisfies(version, '>=3.5')) {
444+
arch = `${arch}-2008plus-ssl`;
445+
}
446+
break;
447+
default:
448+
break;
449+
}
450+
let name: string = `mongodb-${platform}-${arch}`;
451+
434452
this.mongoDBPlatform.getOSVersionString().then(osString => {
435453
osString && (name += `-${osString}`);
436454
}, (error) => {
@@ -506,6 +524,7 @@ export class MongoDBPlatform {
506524
} else if (/debian/i.test(os.dist)) {
507525
resolve(this.getDebianVersionString(os));
508526
} else {
527+
// TODO: 'legacy', 'static'
509528
reject("");
510529
}
511530
});
@@ -520,6 +539,7 @@ export class MongoDBPlatform {
520539
} else if (release >= 7.1) {
521540
name += "71";
522541
} else {
542+
// TODO: 'debian92'
523543
this.debug("using legacy release");
524544
}
525545
return name;
@@ -549,6 +569,7 @@ export class MongoDBPlatform {
549569
} else if (/^5/.test(os.release)) {
550570
name += "55";
551571
} else {
572+
// TODO: 'rhel57'
552573
this.debug("using legacy release");
553574
}
554575
return name;

0 commit comments

Comments
 (0)