cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject git commit: CB-5493 lazy_load now downloads to a temp dir and then moves.
Date Fri, 24 Jan 2014 16:29:15 GMT
Updated Branches:
  refs/heads/master 2676ff88a -> c2830c114


CB-5493 lazy_load now downloads to a temp dir and then moves.

If "cordova create" is interrupted with Ctrl-C while downloading the cordova
library for www, a bad version is stored in ~/.cordova/lib/. That bad version
is then used for future runs of "cordova create" which results in projects with
www dir containing no files except a subfolder named like
cordova-app-hello-world-3.2.0-ee9a86g3


Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/c2830c11
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/c2830c11
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/c2830c11

Branch: refs/heads/master
Commit: c2830c114290f90cf475c14a7de98bac39d68b78
Parents: 2676ff8
Author: Mark Koudritsky <kamrik@chromium.org>
Authored: Thu Jan 23 15:18:44 2014 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Fri Jan 24 11:28:42 2014 -0500

----------------------------------------------------------------------
 src/lazy_load.js | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/c2830c11/src/lazy_load.js
----------------------------------------------------------------------
diff --git a/src/lazy_load.js b/src/lazy_load.js
index 6de1f7c..1b8df00 100644
--- a/src/lazy_load.js
+++ b/src/lazy_load.js
@@ -44,6 +44,7 @@ module.exports = {
     // Returns a promise for the path to the lazy-loaded directory.
     custom:function(url, id, platform, version) {
         var download_dir;
+        var tmp_dir;
         var lib_dir;
 
         // Return early for already-cached remote URL, or for local URLs.
@@ -79,7 +80,13 @@ module.exports = {
                     proxy = conf.get('proxy');
                 }
 
-                shell.mkdir('-p', download_dir);
+                // Create a tmp dir. Using /tmp is a problem because it's often on a different
partition and sehll.mv()
+                // fails in this case with "EXDEV, cross-device link not permitted".
+                tmp_subidr = 'tmp_' + id + '_' + process.pid + '_' + (new Date).valueOf();
+                tmp_dir = path.join(util.libDirectory, 'tmp', tmp_subidr);
+                shell.rm('-rf', tmp_dir);
+                shell.mkdir('-p', tmp_dir);
+
                 var size = 0;
                 var request_options = {uri:url};
                 if (proxy) {
@@ -89,10 +96,10 @@ module.exports = {
                 events.emit('log', 'Downloading ' + id + ' library for ' + platform + '...');
                 var req = request.get(request_options, function(err, res, body) {
                     if (err) {
-                        shell.rm('-rf', download_dir);
+                        shell.rm('-rf', tmp_dir);
                         d.reject(err);
                     } else if (res.statusCode != 200) {
-                        shell.rm('-rf', download_dir);
+                        shell.rm('-rf', tmp_dir);
                         d.reject(new Error('HTTP error ' + res.statusCode + ' retrieving
version ' + version + ' of ' + id + ' for ' + platform));
                     } else {
                         size = body.length;
@@ -100,18 +107,19 @@ module.exports = {
                 });
 
                 req.pipe(zlib.createUnzip())
-                .pipe(tar.Extract({path:download_dir}))
+                .pipe(tar.Extract({path:tmp_dir}))
                 .on('error', function(err) {
-                    shell.rm('-rf', download_dir);
+                    shell.rm('-rf', tmp_dir);
                     d.reject(err);
                 })
                 .on('end', function() {
                     events.emit('verbose', 'Downloaded, unzipped and extracted ' + size +
' byte response.');
                     events.emit('log', 'Download complete');
-                    var entries = fs.readdirSync(download_dir);
-                    var entry = path.join(download_dir, entries[0]);
+                    var entries = fs.readdirSync(tmp_dir);
+                    var entry = path.join(tmp_dir, entries[0]);
+                    shell.mkdir('-p', download_dir);
                     shell.mv('-f', path.join(entry, (platform=='blackberry10'?'blackberry10':''),
'*'), download_dir);
-                    shell.rm('-rf', entry);
+                    shell.rm('-rf', tmp_dir);
                     d.resolve(hooker.fire('after_library_download', {
                         platform:platform,
                         url:url,


Mime
View raw message