You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cd...@apache.org on 2016/10/06 13:49:17 UTC

[5/8] git commit: [flex-utilities] [refs/heads/feature/flash-downloader] - npm-flexjs: if a dependency of falcon fails to download, the installation aborts

npm-flexjs: if a dependency of falcon fails to download, the installation aborts


Project: http://git-wip-us.apache.org/repos/asf/flex-utilities/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-utilities/commit/08389f3a
Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/08389f3a
Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/08389f3a

Branch: refs/heads/feature/flash-downloader
Commit: 08389f3ab08a27cfeaa0d26a45c6e18c3b68dc35
Parents: 4efec79
Author: Josh Tynjala <jo...@apache.org>
Authored: Thu Sep 22 15:39:04 2016 -0700
Committer: Josh Tynjala <jo...@apache.org>
Committed: Thu Sep 22 15:39:04 2016 -0700

----------------------------------------------------------------------
 npm-flexjs/dependencies/ApacheFalcon.js         |  6 ++
 .../dependencies/DownloadUncompressAndCopy.js   | 92 +++++++++++---------
 .../dependencies/download_dependencies.js       |  1 +
 3 files changed, 58 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/08389f3a/npm-flexjs/dependencies/ApacheFalcon.js
----------------------------------------------------------------------
diff --git a/npm-flexjs/dependencies/ApacheFalcon.js b/npm-flexjs/dependencies/ApacheFalcon.js
index 4074fc6..dff2fba 100644
--- a/npm-flexjs/dependencies/ApacheFalcon.js
+++ b/npm-flexjs/dependencies/ApacheFalcon.js
@@ -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();

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/08389f3a/npm-flexjs/dependencies/DownloadUncompressAndCopy.js
----------------------------------------------------------------------
diff --git a/npm-flexjs/dependencies/DownloadUncompressAndCopy.js b/npm-flexjs/dependencies/DownloadUncompressAndCopy.js
index 2546359..2236991 100644
--- a/npm-flexjs/dependencies/DownloadUncompressAndCopy.js
+++ b/npm-flexjs/dependencies/DownloadUncompressAndCopy.js
@@ -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)

http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/08389f3a/npm-flexjs/dependencies/download_dependencies.js
----------------------------------------------------------------------
diff --git a/npm-flexjs/dependencies/download_dependencies.js b/npm-flexjs/dependencies/download_dependencies.js
index ede182d..8d00cf1 100644
--- a/npm-flexjs/dependencies/download_dependencies.js
+++ b/npm-flexjs/dependencies/download_dependencies.js
@@ -162,6 +162,7 @@ function installApacheFlexJS(event)
 function installApacheFalcon(event)
 {
     apacheFalcon.once('complete', handleInstallStepComplete);
+    apacheFalcon.once('abort', handleAbort);
     apacheFalcon.install();
 }