You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/11/14 17:40:49 UTC
git commit: Change cordova serve's project.json to include etags.
Updated Branches:
refs/heads/master 99854ad6b -> 445a5fdbf
Change cordova serve's project.json to include etags.
Allows App Harness to only update changed files.
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/445a5fdb
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/445a5fdb
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/445a5fdb
Branch: refs/heads/master
Commit: 445a5fdbf15303e6c5a792604056525a09159bcc
Parents: 99854ad
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Nov 14 11:40:13 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Thu Nov 14 11:40:13 2013 -0500
----------------------------------------------------------------------
src/serve.js | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/445a5fdb/src/serve.js
----------------------------------------------------------------------
diff --git a/src/serve.js b/src/serve.js
index 59ffb0a..1d7f463 100644
--- a/src/serve.js
+++ b/src/serve.js
@@ -17,6 +17,7 @@
under the License.
*/
var cordova_util = require('./util'),
+ crypto = require('crypto'),
path = require('path'),
shell = require('shelljs'),
platforms = require('../platforms'),
@@ -162,6 +163,26 @@ function launchServer(projectRoot, port) {
return server;
}
+function calculateMd5(fileName) {
+ var BUF_LENGTH = 64*1024,
+ buf = new Buffer(BUF_LENGTH),
+ bytesRead = BUF_LENGTH,
+ pos = 0,
+ fdr = fs.openSync(fileName, 'r');
+
+ try {
+ var md5sum = crypto.createHash('md5');
+ while (bytesRead === BUF_LENGTH) {
+ bytesRead = fs.readSync(fdr, buf, 0, BUF_LENGTH, pos);
+ pos += bytesRead;
+ md5sum.update(buf.slice(0, bytesRead));
+ }
+ } finally {
+ fs.closeSync(fdr);
+ }
+ return md5sum.digest('hex');
+}
+
function processAddRequest(request, response, platformId, projectRoot) {
var parser = new platforms[platformId].parser(path.join(projectRoot, 'platforms', platformId));
var wwwDir = parser.www_dir();
@@ -170,7 +191,7 @@ function processAddRequest(request, response, platformId, projectRoot) {
'wwwPath': '/' + platformId + '/www',
'wwwFileList': shell.find(wwwDir)
.filter(function(a) { return !fs.statSync(a).isDirectory() && !/(^\.)|(\/\.)/.test(a) })
- .map(function(a) { return a.slice(wwwDir.length); })
+ .map(function(a) { return {'path': a.slice(wwwDir.length), 'etag': '' + calculateMd5(a)}; })
};
console.log('200 ' + request.url);
response.writeHead(200, {