From f1bf2d7598ce581cd9cfee835f567dd0e3b0a093 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 11 Sep 2012 08:59:34 -0400 Subject: [PATCH] added linux and windows versions of watch functions --- index.html | 2 +- lib/cloudfunc.js | 2 +- lib/server/appcache.js | 30 +++++++++++++++++++++++++----- server.js | 2 +- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index fb95fe31..96a56660 100644 --- a/index.html +++ b/index.html @@ -1,5 +1,5 @@ - + diff --git a/lib/cloudfunc.js b/lib/cloudfunc.js index 95fb3a4e..9e7d9eea 100644 --- a/lib/cloudfunc.js +++ b/lib/cloudfunc.js @@ -25,7 +25,7 @@ var CloudFunc = { SHORTNAMELENGTH : 16 }; -/* +/*1 * Функция убирает последний слеш, * если он - последний символ строки */ diff --git a/lib/server/appcache.js b/lib/server/appcache.js index cfe461f1..a04babc3 100644 --- a/lib/server/appcache.js +++ b/lib/server/appcache.js @@ -1,16 +1,18 @@ var fs = require('fs'); +var crypto = require('crypto'); /* varible contain all watched file names * {name: true} */ -var FileNames = {}; -var i=0; +var FileNames = {}; /* function thet use for crossplatform * access to fs.watch or fs.watchFile function */ -var fs_watch = null; -var on_fs_watch =null; +var fs_watch = null; +var on_fs_watch = null; +var firstFileRead_b = true; +var Manifest = ''; setWatachFunctions(); @@ -38,9 +40,13 @@ exports.watch = function(pFileName){ catch(pError){ console.log(pError); } - + Manifest += pFileName + '\n'; FileNames[pFileName] = true; } + else if(firstFileRead_b){ + processManifest(); + firstFileRead_b = false; + } }; function onWatch (pFileName){ @@ -55,4 +61,18 @@ function onWatchFile(pFileName){ if(pCurr.mtime !== pCurr.pPrev.mtime) console.log('file ' + pFileName + 'is changed'); }; +} + +function processManifest(){ + Manifest = 'CACHE MANIFEST\n' + + '#' + new Date() + '\n' + + 'CACHE:\n' + + Manifest + + 'NETWORK:\n' + + '*'; + + console.log(Manifest); + fs.writeFile('cloudcmd.appcache', Manifest, function(){ + console.log('cloudcmd.appcache refreshed'); + }); } \ No newline at end of file diff --git a/server.js b/server.js index 7a4ed27a..10ec629b 100644 --- a/server.js +++ b/server.js @@ -338,7 +338,7 @@ CloudServer._controller = function(pReq, pRes) console.log('reading '+lName); /* watching is file changed */ - CloudServer.AppCache.watch(lName); + //CloudServer.AppCache.watch(lName); /* сохраняем указатель на response и имя */ CloudServer.Responses[lName] = pRes;