Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

check mtime rather than ino in fileWatcher

  • Loading branch information...
commit b5061c97904e6980ab14b07ce8f72f1c56567414 1 parent 22a5bca
@alunny alunny authored
Showing with 29 additions and 13 deletions.
  1. +2 −2 main.js
  2. +27 −11 test/test_monitor.js
View
4 main.js
@@ -54,7 +54,7 @@ exports.watchTree = function ( root, options, callback ) {
var fileWatcher = function (f) {
fs.watchFile(f, options, function (c, p) {
// Check if anything actually changed in stat
- if (files[f] && !files[f].isDirectory() && c.nlink !== 0 && files[f].ino == c.ino) return;
+ if (files[f] && !files[f].isDirectory() && c.nlink !== 0 && files[f].mtime == c.mtime) return;
files[f] = c;
if (!files[f].isDirectory()) callback(f, c, p);
else {
@@ -105,4 +105,4 @@ exports.createMonitor = function (root, options, cb) {
})
}
-exports.walk = walk;
+exports.walk = walk;
View
38 test/test_monitor.js
@@ -1,15 +1,31 @@
var watch = require('../main')
, assert = require('assert')
+ , path = require('path')
+ , fs = require('fs')
+ , target = path.join(__dirname, "d/t")
;
-watch.createMonitor(__dirname, function (monitor) {
- monitor.on('created', function (f) {
- console.log('created '+f)
- })
- monitor.on('removed', function (f) {
- console.log('removed '+f)
- })
- monitor.on('changed', function (f) {
- console.log('changed '+f)
- })
-});
+function clearFile() {
+ fs.writeFileSync(target, '')
+}
+
+clearFile()
+
+// test if changed event is fired correctly
+watch.createMonitor(__dirname, { interval: 150 },
+ function (monitor) {
+ monitor.once('changed', function (f) {
+ assert.equal(f, target);
+ clearFile();
+ process.exit(0)
+ })
+
+ fs.writeFile(target, 'Test Write\n', function (err) {
+ if (err) throw err;
+
+ setTimeout(function () {
+ // should have got the other assert done by now
+ assert.ok(false);
+ }, 300);
+ })
+});
Please sign in to comment.
Something went wrong with that request. Please try again.