Skip to content
Permalink
Browse files
npm-flexjs: if a dependency of falcon fails to download, the installa…
…tion aborts
  • Loading branch information
joshtynjala committed Sep 22, 2016
1 parent 4efec79 commit 08389f3ab08a27cfeaa0d26a45c6e18c3b68dc35
Showing 3 changed files with 58 additions and 41 deletions.
@@ -289,11 +289,17 @@ ApacheFalcon.downloadNextDependency = function()
}
else
{
duc.once("installFail", handleDependencyInstallFail);
duc.once("installComplete", handleDependencyInstallComplete);
duc.install(falconDependencies[currentStep]);
}
};

function handleDependencyInstallFail(event)
{
ApacheFalcon.emit('abort');
}

function handleDependencyInstallComplete(event)
{
ApacheFalcon.downloadNextDependency();
@@ -31,49 +31,59 @@ DownloadUncompressAndCopy.downloadFile = function(item)
console.log('Downloading: ' + item.url + item.remoteFileName);
request
.get(item.url + item.remoteFileName)
.pipe(fs.createWriteStream(constants.DOWNLOADS_FOLDER + item.remoteFileName)
.on('close', function(){
console.log('Finished downloading: ' + item.url + item.remoteFileName);
if(item.unzip)
{//Unzip
console.log('Uncompressing: ' + constants.DOWNLOADS_FOLDER + item.remoteFileName);
fs.createReadStream(constants.DOWNLOADS_FOLDER + item.remoteFileName)
.pipe(unzip.Parse())
.on('entry', function (entry) {
var fileName = entry.path;
var type = entry.type; // 'Directory' or 'File'
var size = entry.size;
if (fileName === item.pathOfFileToBeCopiedFrom) {
entry.pipe(fs.createWriteStream(item.pathOfFileToBeCopiedTo));
} else {
entry.autodrain();
}
})
.on('finish', function(){
console.log('Finished uncompressing: ' + constants.DOWNLOADS_FOLDER + item.remoteFileName + ' to: ' + item.destinationPath + item.destinationFileName);
DownloadUncompressAndCopy.emit('installComplete');
})
.on('response', function(response){
if(response.statusCode != 200)
{
console.log('Download failed with status code: ' + response.statusCode);
DownloadUncompressAndCopy.emit('installFail');
}
else
{
response.pipe(fs.createWriteStream(constants.DOWNLOADS_FOLDER + item.remoteFileName)
.on('close', function(){
console.log('Finished downloading: ' + item.url + item.remoteFileName);
if(item.unzip)
{//Unzip
console.log('Uncompressing: ' + constants.DOWNLOADS_FOLDER + item.remoteFileName);
fs.createReadStream(constants.DOWNLOADS_FOLDER + item.remoteFileName)
.pipe(unzip.Parse())
.on('entry', function (entry) {
var fileName = entry.path;
var type = entry.type; // 'Directory' or 'File'
var size = entry.size;
if (fileName === item.pathOfFileToBeCopiedFrom) {
entry.pipe(fs.createWriteStream(item.pathOfFileToBeCopiedTo));
} else {
entry.autodrain();
}
})
.on('finish', function(){
console.log('Finished uncompressing: ' + constants.DOWNLOADS_FOLDER + item.remoteFileName + ' to: ' + item.destinationPath + item.destinationFileName);
DownloadUncompressAndCopy.emit('installComplete');
})

}
else
{//Just copy
if((constants.DOWNLOADS_FOLDER + item.remoteFileName === item.destinationPath + item.destinationFileName))
{
DownloadUncompressAndCopy.emit('installComplete');
}
else
{
fs.createReadStream(constants.DOWNLOADS_FOLDER + item.remoteFileName)
.pipe(fs.createWriteStream(item.destinationPath + item.destinationFileName))
.on('close', function(){
console.log("Copied " + constants.DOWNLOADS_FOLDER + item.remoteFileName + " to " +
item.destinationPath + item.destinationFileName);
}
else
{//Just copy
if((constants.DOWNLOADS_FOLDER + item.remoteFileName === item.destinationPath + item.destinationFileName))
{
DownloadUncompressAndCopy.emit('installComplete');
});
}
}
})
);
}
else
{
fs.createReadStream(constants.DOWNLOADS_FOLDER + item.remoteFileName)
.pipe(fs.createWriteStream(item.destinationPath + item.destinationFileName))
.on('close', function(){
console.log("Copied " + constants.DOWNLOADS_FOLDER + item.remoteFileName + " to " +
item.destinationPath + item.destinationFileName);
DownloadUncompressAndCopy.emit('installComplete');
});
}
}
})
);
}
})
};

DownloadUncompressAndCopy.install = function(item)
@@ -162,6 +162,7 @@ function installApacheFlexJS(event)
function installApacheFalcon(event)
{
apacheFalcon.once('complete', handleInstallStepComplete);
apacheFalcon.once('abort', handleAbort);
apacheFalcon.install();
}

0 comments on commit 08389f3

Please sign in to comment.