Repository: cordova-app-harness
Updated Branches:
  refs/heads/master 7a508c3bb -> 32145b811


Bump HarnessServer protocol version, update comments, make bulkMove a bit safer


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/eafb3494
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/eafb3494
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/eafb3494

Branch: refs/heads/master
Commit: eafb3494809a87f21b4fe5d24dfd046a4e796477
Parents: 7a508c3
Author: Andrew Grieve <[email protected]>
Authored: Tue Jun 17 15:29:53 2014 -0400
Committer: Andrew Grieve <[email protected]>
Committed: Tue Jun 17 16:27:42 2014 -0400

----------------------------------------------------------------------
 www/cdvah/js/DirectoryManager.js | 33 +++++++++++++++-----------------
 www/cdvah/js/HarnessServer.js    | 36 +++++++++++++++++++++++------------
 2 files changed, 39 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/eafb3494/www/cdvah/js/DirectoryManager.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/DirectoryManager.js b/www/cdvah/js/DirectoryManager.js
index cf782f0..da39c82 100644
--- a/www/cdvah/js/DirectoryManager.js
+++ b/www/cdvah/js/DirectoryManager.js
@@ -47,8 +47,8 @@
         };
 
         DirectoryManager.prototype.deleteAll = function() {
-            this._assetManifest = null;
-            this._assetManifestEtag = null;
+            this._assetManifest = {};
+            this._assetManifestEtag = 0;
             window.clearTimeout(this._flushTimerId);
             return ResourcesLoader.delete(this.rootURL);
         };
@@ -96,24 +96,21 @@
             return ResourcesLoader.writeFileContents(this.rootURL + 
ASSET_MANIFEST, stringContents);
         };
 
-        DirectoryManager.prototype.bulkAddFile = function(zipAssetManifest, 
srcURL) {
+        DirectoryManager.prototype.bulkAddFile = function(newAssetManifest, 
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 );
-            })
+            return this.deleteAll()
             .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']);
-                 }
+                return ResourcesLoader.moveFile(srcURL, self.rootURL);
+            }).then(function() {
+                var keys = Object.keys(newAssetManifest);
+                return $q.when().then(function next() {
+                    var key = keys.shift();
+                    if (!key) {
+                        return;
+                    }
+                    return self._updateManifest(key, newAssetManifest[key])
+                    .then(next);
+                });
             });
         };
 

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/eafb3494/www/cdvah/js/HarnessServer.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/HarnessServer.js b/www/cdvah/js/HarnessServer.js
index 1a46513..bfe7240 100644
--- a/www/cdvah/js/HarnessServer.js
+++ b/www/cdvah/js/HarnessServer.js
@@ -50,16 +50,22 @@
 //
 // Send a set 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";
-// The zip file must contain a zipassetmanifest.json file at its root that is 
a map of "srcPath"->{"path":dstPath, "etag":"0"}.
+// The zip file must contain a zipassetmanifest.json file at its root that is 
a map of "srcPath"->"$etag"}.
 //
 // 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"}.
+// The zip file must contain a zipassetmanifest.json file at its root that is 
a map of "srcPath"->"$etag"}.
 // With this method, the files are moved one at a time and will overwrite any 
existing file of the same name.
 //
+// PROTOCOL CHANGES BY VERSION:
+// Version 3:
+//   - Allow zipassetmanifest to use { "srcPath" => "$etag" } rather than { 
"srcPath" => { "etag": "foo" } } (still supports either though).
+//   - Removed support for custom dstPath within zipassetmanifest.json
+//   - Sped up zippush by doing a directory move rather than per-file moves.
+//   - Added ?movetype=file to zippush command for old per-file behaviour.
     myApp.factory('HarnessServer', ['$q', 'HttpServer', 'ResourcesLoader', 
'AppHarnessUI', 'AppsService', 'notifier', 'APP_VERSION', function($q, 
HttpServer, ResourcesLoader, AppHarnessUI, AppsService, notifier, APP_VERSION) {
 
-        var PROTOCOL_VER = 2;
+        var PROTOCOL_VER = 3;
         var server = null;
         var listenAddress = null;
 
@@ -272,23 +278,29 @@
                 })
                 .then(function() {
                     // This file looks like:
-                    // {"path/within/zip": { "path": "dest/path", "etag": 
"foo" }}
+                    // {"path/within/zip": "$etag" }
                     return ResourcesLoader.readJSONFileContents(tmpDirUrl + 
'zipassetmanifest.json');
                 }, null, function(unzipPercentage) {
                     app.updatingStatus = unzipPercentage;
                 })
                 .then(function(zipAssetManifest) {
+                    // Support old format of {"path/within/zip": {"etag": 
"$etag" }}
+                    Object.keys(zipAssetManifest).forEach(function(k) {
+                        if (typeof zipAssetManifest[k] != 'string') {
+                            zipAssetManifest[k] = zipAssetManifest[k]['etag'];
+                        }
+                    });
                     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);
+                            if (zipAssetManifest['www/cordova_plugins.js']) {
+                                zipAssetManifest['orig-cordova_plugins.js'] = 
zipAssetManifest['www/cordova_plugins.js'];
+                                delete 
zipAssetManifest['www/cordova_plugins.js'];
+                                return ResourcesLoader.moveFile(tmpDirUrl + 
'www/cordova_plugins.js', tmpDirUrl + 'orig-cordova_plugins.js');
+                            }
+                        }).then(function() {
+                            return 
app.directoryManager.bulkAddFile(zipAssetManifest, tmpDirUrl);
                         });
                     } else {
                         var keys = Object.keys(zipAssetManifest);
@@ -297,7 +309,7 @@
                         .then(function next() {
                             var k = keys.shift();
                             if (k) {
-                                return  importFile(tmpDirUrl + k, 
zipAssetManifest[k]['path'], app, zipAssetManifest[k]['etag'])
+                                return importFile(tmpDirUrl + k, k, app, 
zipAssetManifest[k])
                                 .then(next);
                             }
                         });

Reply via email to