11const fs = require ( "fs" ) ;
2- const { dirname, join } = require ( "path" ) ;
2+ const { dirname, join, EOL } = require ( "path" ) ;
33const os = require ( "os" ) ;
44const child_process = require ( "child_process" ) ;
55
@@ -12,6 +12,7 @@ const BUNDLE_PREAMBLE_PATH = join(__dirname, "snapshot-generator-tools/bundle-pr
1212const BUNDLE_ENDING_PATH = join ( __dirname , "snapshot-generator-tools/bundle-ending.js" ) ;
1313const INCLUDE_GRADLE_PATH = join ( __dirname , "snapshot-generator-tools/include.gradle" ) ;
1414const MKSNAPSHOT_TOOLS_DOWNLOAD_ROOT_URL = "https://raw.githubusercontent.com/NativeScript/mksnapshot-tools/production/" ;
15+ const MKSNAPSHOT_TOOLS_DOWNLOAD_TIMEOUT = 60000 ;
1516const SNAPSHOT_BLOB_NAME = "TNSSnapshot" ;
1617
1718function shellJsExecuteInDir ( dir , action ) {
@@ -66,7 +67,20 @@ SnapshotGenerator.prototype.downloadMksnapshotTool = function(snapshotToolsPath,
6667
6768 const downloadUrl = MKSNAPSHOT_TOOLS_DOWNLOAD_ROOT_URL + mksnapshotToolRelativePath ;
6869 createDirectory ( dirname ( mksnapshotToolPath ) ) ;
69- snapshotToolsDownloads [ mksnapshotToolPath ] = downloadFile ( downloadUrl , mksnapshotToolPath ) ;
70+ snapshotToolsDownloads [ mksnapshotToolPath ] = downloadFile ( downloadUrl , mksnapshotToolPath , MKSNAPSHOT_TOOLS_DOWNLOAD_TIMEOUT ) ;
71+ snapshotToolsDownloads [ mksnapshotToolPath ] . catch ( err => {
72+ const errorMessage = err && err . message ? err . message : "" ;
73+ let cleanupError = "" ;
74+ try {
75+ fs . unlinkSync ( mksnapshotToolPath ) ;
76+ } catch ( unlinkErr ) {
77+ if ( unlinkErr && unlinkErr . code !== "ENOENT" ) {
78+ cleanupError = `${ EOL } Failed to cleanup mksnapshot tool.` ;
79+ }
80+ }
81+
82+ throw new Error ( `Failed to download mksnapshot tool. Error: ${ errorMessage } .${ cleanupError } ` ) ;
83+ } ) ;
7084 return snapshotToolsDownloads [ mksnapshotToolPath ] ;
7185}
7286
0 commit comments