Skip to content

Commit b2370b9

Browse files
wingedfoxnodkz
authored andcommitted
fix: download legacy build for unknown os (thanks @wingedfox)
* GH-43 download legacy build for unknown os * style: fix eslint warnings
1 parent bd275e7 commit b2370b9

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/util/MongoBinaryDownloadUrl.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ export default class MongoBinaryDownloadUrl {
8282
} else if (/mint/i.test(os.dist)) {
8383
return this.getMintVersionString(os);
8484
}
85-
throw new Error(`Cannot determine version string for ${JSON.stringify(os)}`);
85+
console.warn(`Unknown linux distro ${os.dist}, falling back to legacy MongoDB build`);
86+
return this.getLegacyVersionString(os);
8687
}
8788

8889
getDebianVersionString(os: OS): string {
@@ -135,6 +136,11 @@ export default class MongoBinaryDownloadUrl {
135136
return 'ubuntu1404';
136137
}
137138

139+
// eslint-disable-next-line no-unused-vars
140+
getLegacyVersionString(os: OS): string {
141+
return '';
142+
}
143+
138144
getSuseVersionString(os: any): string {
139145
const [release]: [string | null] = os.release.match(/(^11|^12)/) || [null];
140146

src/util/__tests__/MongoBinaryDownloadUrl-test.js

+26
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ describe('MongoBinaryDownloadUrl', () => {
4444
'https://downloads.mongodb.org/win32/mongodb-win32-x86_64-3.4.4.zip'
4545
);
4646
});
47+
48+
it('fallback', async () => {
49+
const du = new MongoBinaryDownloadUrl({
50+
platform: 'linux',
51+
arch: 'x64',
52+
version: '3.4.4',
53+
os: {
54+
dist: 'Gentoo Linux',
55+
},
56+
});
57+
expect(await du.getDownloadUrl()).toBe(
58+
'https://downloads.mongodb.org/linux/mongodb-linux-x86_64-3.4.4.tgz'
59+
);
60+
});
4761
});
4862

4963
describe('getUbuntuVersionString()', () => {
@@ -154,4 +168,16 @@ describe('MongoBinaryDownloadUrl', () => {
154168
expect(downloadUrl.getMintVersionString({ dist: 'Linux Mint' })).toBe('ubuntu1404');
155169
});
156170
});
171+
172+
describe('getLegacyVersionString', () => {
173+
const downloadUrl = new MongoBinaryDownloadUrl({
174+
platform: 'linux',
175+
arch: 'x64',
176+
version: '3.4.4',
177+
});
178+
179+
it('should return an archive name for Gentoo Linux', () => {
180+
expect(downloadUrl.getLegacyVersionString({ dist: 'Gentoo Linux' })).toBe('');
181+
});
182+
});
157183
});

0 commit comments

Comments
 (0)