added linux and windows versions of watch functions

This commit is contained in:
coderaiser 2012-09-11 08:59:34 -04:00
parent f46cd4a1ff
commit f1bf2d7598
4 changed files with 28 additions and 8 deletions

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html> <!-- manifest=cloudcmd.appcache -->
<head>
<meta charset="utf-8">
<!-- mobile first design -->

View file

@ -25,7 +25,7 @@ var CloudFunc = {
SHORTNAMELENGTH : 16
};
/*
/*1
* Функция убирает последний слеш,
* если он - последний символ строки
*/

View file

@ -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');
});
}

View file

@ -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;