Skip to content

Commit 4e40bd9

Browse files
cmosghnodkz
authored andcommitted
fix: win32 binary path fix
* win32 binary path fix * cleaned up for prettier * Better performance Creation different functions are better than check OS inside one filter function for every record. closes #24
1 parent 9a865d6 commit 4e40bd9

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/util/MongoBinaryDownload.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export default class MongoBinaryDownload {
6868
}
6969

7070
async getMongodPath(): Promise<string> {
71-
const mongodPath = path.resolve(this.downloadDir, this.version, 'mongod');
71+
const binaryName = this.platform === 'win32' ? 'mongod.exe' : 'mongod';
72+
const mongodPath = path.resolve(this.downloadDir, this.version, binaryName);
7273
if (this.locationExists(mongodPath)) {
7374
return mongodPath;
7475
}
@@ -115,20 +116,27 @@ export default class MongoBinaryDownload {
115116
}
116117

117118
async extract(mongoDBArchive: string): Promise<string> {
119+
const binaryName = this.platform === 'win32' ? 'mongod.exe' : 'mongod';
118120
const extractDir = path.resolve(this.downloadDir, this.version);
119121
this.debug(`extract(): ${extractDir}`);
120122
await fs.ensureDir(extractDir);
123+
124+
const filter =
125+
this.platform === 'win32'
126+
? file => /bin\/mongod.exe$/.test(file.path)
127+
: file => /bin\/mongod$/.test(file.path);
128+
121129
await decompress(mongoDBArchive, extractDir, {
122130
// extract only `bin/mongod` file
123-
filter: file => /bin\/mongod$/.test(file.path),
131+
filter,
124132
// extract to root folder
125133
map: file => {
126134
file.path = path.basename(file.path); // eslint-disable-line
127135
return file;
128136
},
129137
});
130138

131-
if (!this.locationExists(path.resolve(this.downloadDir, this.version, 'mongod'))) {
139+
if (!this.locationExists(path.resolve(this.downloadDir, this.version, binaryName))) {
132140
throw new Error(`MongoBinaryDownload: missing mongod binary in ${mongoDBArchive}`);
133141
}
134142
return extractDir;

0 commit comments

Comments
 (0)