cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From drk...@apache.org
Subject git commit: [CB6947] move app directory by default. use parameter movetype='file' to do merge
Date Tue, 17 Jun 2014 13:49:50 GMT
Repository: cordova-app-harness
Updated Branches:
  refs/heads/master e1994aa57 -> 7a508c3bb


[CB6947] move app directory by default.
use parameter movetype='file' to do merge


Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/7a508c3b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/7a508c3b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/7a508c3b

Branch: refs/heads/master
Commit: 7a508c3bbb525680f7eda359a16d63a45c559d74
Parents: e1994aa
Author: David Kemp <drkemp@chromium.org>
Authored: Tue Jun 17 08:08:55 2014 -0400
Committer: David Kemp <drkemp@chromium.org>
Committed: Tue Jun 17 08:08:55 2014 -0400

----------------------------------------------------------------------
 www/cdvah/js/DirectoryManager.js | 21 +++++++++++++++++++
 www/cdvah/js/HarnessServer.js    | 39 +++++++++++++++++++++++++++--------
 2 files changed, 51 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/7a508c3b/www/cdvah/js/DirectoryManager.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/DirectoryManager.js b/www/cdvah/js/DirectoryManager.js
index 9f0c737..cf782f0 100644
--- a/www/cdvah/js/DirectoryManager.js
+++ b/www/cdvah/js/DirectoryManager.js
@@ -96,6 +96,27 @@
             return ResourcesLoader.writeFileContents(this.rootURL + ASSET_MANIFEST, stringContents);
         };
 
+        DirectoryManager.prototype.bulkAddFile = function(zipAssetManifest, srcURL) {
+            var self = this;
+            return ResourcesLoader.moveFile(srcURL, self.rootURL )
+            .then(function() {
+                 var src=self.rootURL+'www/cordova_plugins.js';
+                 var dest = self.rootURL+'orig-cordova_plugins.js';
+                 return ResourcesLoader.moveFile(src,dest );
+            })
+            .then(function() {
+                 var keys=Object.keys(zipAssetManifest);
+                 for(var i=0;i<keys.length;i++) {
+                     var k = keys[i];
+                     var destPath = zipAssetManifest[k]['path'];
+                     if (destPath == 'www/cordova_plugins.js') {
+                         destPath = 'orig-cordova_plugins.js';
+                     }
+                     self._updateManifest(destPath, zipAssetManifest[k]['etag']);
+                 }
+            });
+        };
+
         DirectoryManager.prototype.addFile = function(srcURL, relativePath, etag) {
             var self = this;
             return ResourcesLoader.moveFile(srcURL, this.rootURL + relativePath)

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/7a508c3b/www/cdvah/js/HarnessServer.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/HarnessServer.js b/www/cdvah/js/HarnessServer.js
index 557f98b..1a46513 100644
--- a/www/cdvah/js/HarnessServer.js
+++ b/www/cdvah/js/HarnessServer.js
@@ -52,6 +52,11 @@
 //     cat file | curl -v -X POST -d @- "http://$IP_ADDRESS:2424/zippush?appId=a.b.c&appType=cordova"
 // The zip file must contain a zipassetmanifest.json file at its root that is a map of "srcPath"->{"path":dstPath,
"etag":"0"}.
 //
+// Send a partial update of files within the given app ID (or the first app if none is given):
+//     cat file | curl -v -X POST -d @- "http://$IP_ADDRESS:2424/zippush?appId=a.b.c&appType=cordova&movetype=file"
+// The zip file must contain a zipassetmanifest.json file at its root that is a map of "srcPath"->{"path":dstPath,
"etag":"0"}.
+// With this method, the files are moved one at a time and will overwrite any existing file
of the same name.
+//
     myApp.factory('HarnessServer', ['$q', 'HttpServer', 'ResourcesLoader', 'AppHarnessUI',
'AppsService', 'notifier', 'APP_VERSION', function($q, HttpServer, ResourcesLoader, AppHarnessUI,
AppsService, notifier, APP_VERSION) {
 
         var PROTOCOL_VER = 2;
@@ -251,6 +256,7 @@
             var appId = req.getQueryParam('appId');
             var appType = req.getQueryParam('appType') || 'cordova';
             var manifestEtag = req.getQueryParam('manifestEtag');
+            var movetype = req.getQueryParam('movetype') || 'bulk';
             return AppsService.getAppById(appId, appType)
             .then(function(app) {
                 if (manifestEtag && app.directoryManager.getAssetManifestEtag() !==
manifestEtag) {
@@ -272,15 +278,30 @@
                     app.updatingStatus = unzipPercentage;
                 })
                 .then(function(zipAssetManifest) {
-                    var keys = Object.keys(zipAssetManifest);
-                    return $q.when()
-                    .then(function next() {
-                        var k = keys.shift();
-                        if (k) {
-                            return importFile(tmpDirUrl + k, zipAssetManifest[k]['path'],
app, zipAssetManifest[k]['etag'])
-                            .then(next);
-                        }
-                    });
+                    if (movetype == 'bulk') {
+                        console.log('Moving files in bulk');
+                        return $q.when()
+                        .then(function(){
+                            // get the source base path from the first file
+                            // all files need to be in the same place
+                            var firstfile = Object.keys(zipAssetManifest)[0];
+                            var fpath = tmpDirUrl + firstfile;
+                            var pathendposition = fpath.lastIndexOf(zipAssetManifest[firstfile]['path']);
+                            var fromurl = fpath.substr(0,pathendposition-1);
+                            return app.directoryManager.bulkAddFile(zipAssetManifest, fromurl);
+                        });
+                    } else {
+                        var keys = Object.keys(zipAssetManifest);
+                        console.log('Moving '+keys.length+ ' files separately');
+                        return $q.when()
+                        .then(function next() {
+                            var k = keys.shift();
+                            if (k) {
+                                return  importFile(tmpDirUrl + k, zipAssetManifest[k]['path'],
app, zipAssetManifest[k]['etag'])
+                                .then(next);
+                            }
+                        });
+                    }
                 }, function() {
                     throw new HttpServer.ResponseException(400, 'Zip file missing zipassetmanifest.json');
                 })


Mime
View raw message