44import os from 'os' ;
55import url from 'url' ;
66import path from 'path' ;
7- import fs from 'fs-extra ' ;
7+ import fs from 'fs' ;
88import md5File from 'md5-file' ;
99import https from 'https' ;
1010import HttpsProxyAgent from 'https-proxy-agent' ;
@@ -83,7 +83,9 @@ export default class MongoBinaryDownload {
8383 version : this . version ,
8484 } ) ;
8585
86- await fs . ensureDir ( this . downloadDir ) ;
86+ if ( ! fs . existsSync ( this . downloadDir ) ) {
87+ fs . mkdirSync ( this . downloadDir ) ;
88+ }
8789
8890 const downloadUrl = await mbdUrl.getDownloadUrl();
8991 const mongoDBArchive = await this.download(downloadUrl);
@@ -95,8 +97,9 @@ export default class MongoBinaryDownload {
9597 }
9698
9799 async checkMd5 ( mongoDBArchiveMd5 : string , mongoDBArchive : string ) {
98- const signatureContent = ( await fs . readFile ( mongoDBArchiveMd5 ) ) . toString ( 'UTF-8' ) ;
99- const md5Remote = signatureContent . match ( / ( .* ?) \s / ) [ 1 ] ;
100+ const signatureContent = fs . readFileSync ( mongoDBArchiveMd5 ) . toString ( 'UTF-8' ) ;
101+ const m = signatureContent . match ( / ( .* ?) \s / ) ;
102+ const md5Remote = m ? m [ 1 ] : null ;
100103 const md5Local = md5File . sync ( mongoDBArchive ) ;
101104 if ( md5Remote !== md5Local ) {
102105 throw new Error ( 'MongoBinaryDownload: md5 check is failed' ) ;
@@ -142,7 +145,10 @@ export default class MongoBinaryDownload {
142145 const binaryName = this . platform === 'win32' ? 'mongod.exe' : 'mongod' ;
143146 const extractDir = path . resolve ( this . downloadDir , this . version ) ;
144147 this . debug ( `extract(): ${ extractDir } ` ) ;
145- await fs . ensureDir ( extractDir ) ;
148+
149+ if ( ! fs . existsSync ( extractDir ) ) {
150+ fs . mkdirSync ( extractDir ) ;
151+ }
146152
147153 let filter;
148154 if (this.platform === 'win32') {
@@ -185,11 +191,10 @@ export default class MongoBinaryDownload {
185191 response . pipe ( fileStream ) ;
186192
187193 fileStream . on ( 'finish' , ( ) => {
188- fileStream . close ( ( ) => {
189- fs . renameSync ( tempDownloadLocation , downloadLocation ) ;
190- this . debug ( `renamed ${ tempDownloadLocation } to ${ downloadLocation } ` ) ;
191- resolve ( downloadLocation ) ;
192- } ) ;
194+ fileStream . close ( ) ;
195+ fs . renameSync ( tempDownloadLocation , downloadLocation ) ;
196+ this . debug ( `renamed ${ tempDownloadLocation } to ${ downloadLocation } ` ) ;
197+ resolve ( downloadLocation ) ;
193198 } ) ;
194199
195200 response . on ( 'data' , ( chunk : any ) => {
0 commit comments