Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing some bugs in strict mode. Seems to work.

  • Loading branch information...
commit b787bb3454ff4e167f28c60adc867cbecdd7839d 1 parent 2018bb8
@jslatts authored
View
8 Readme.md
@@ -49,12 +49,10 @@ Stalker will also take a second callback that will be fired when files are remov
The removal callback also works in batch mode.
## Running tests
-
- npm install vows
- vows spec/*
-You can also run example/*.js and play around adding and removing files from the
-example directory:
+I couldn't handle vows.js anymore. I ripped it out. Will replace with something
+else in the future. For now, run example/*.js and play around adding and
+removing files from the example directory:
node example/test.js
View
0  example/test-norecurse.js → example/test_norecurse.js
File renamed without changes
View
10 example/test_strict.js
@@ -0,0 +1,10 @@
+stalker = require('../');
+
+stalker.watch('./example', {strict: true}, function(err, f) {
+ if (err) {
+ console.log('Error was ' + err);
+ return;
+ }
+ console.log('I see ' + f);
+});
+
View
22 lib/stalker.js
@@ -20,17 +20,24 @@
var folderChanged = function(folderPath, fnAdd, fnRemove) {
return function (event, filename) {
- if (event === 'rename') { return; }
+ var reset = true;
+ if (event === 'change') {
+ reset = false;
+ }
//Because of the goofy fs.watch() api, we have to close and recreate the
//file watch handle. Except sometimes the file was moved and this blows up
//So close, then check and recreate if it still exists
- handles[folderPath].close();
+ if (reset) {
+ handles[folderPath].close();
+ }
fs.stat(folderPath, function(err) {
if (err) { return; }
- handles[folderPath] = fs.watch(folderPath, folderChanged(folderPath, fnAdd, fnRemove));
+ if (reset) {
+ handles[folderPath] = fs.watch(folderPath, folderChanged(folderPath, fnAdd, fnRemove));
+ }
fs.readdir(folderPath, function _readdir(err, files) {
if (err) { console.log('read');return fnAdd && fnAdd(err); }
@@ -152,9 +159,9 @@
var nPath = path.resolve(reqPath);
- options = opts
- options.recurse = typeof options.recurse === 'undefined' ? true : options.recurse
- options.strict = typeof options.strict === 'undefined' ? false : options.strict
+ options = opts;
+ options.recurse = typeof options.recurse === 'undefined' ? true : options.recurse;
+ options.strict = typeof options.strict === 'undefined' ? false : options.strict;
//If a buffer time is passed, then wrap the passed in callback
if (typeof options.buffer === 'number') {
@@ -220,8 +227,7 @@
return fnAdd && fnAdd('Path does not exist: ' + nPath);
}
- var depth = options.recurse ? Infinity : 1
-// console.log('recurse is ' + options.recurse + ' and depth at start ' + depth)
+ var depth = options.recurse ? Infinity : 1;
watchFolderTree(nPath, fnAdd, fnRemove, depth);
});
};
View
4 lib/watcher.js
@@ -39,8 +39,8 @@
//strict is truthy.
checkFile: function (fPath, strict, fn) {
if (typeof(strict) === 'function') {
- fn = strict
- strict = false
+ fn = strict;
+ strict = false;
}
var dir = path.dirname(fPath);
Please sign in to comment.
Something went wrong with that request. Please try again.