Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

checking mtime rather than ino in fileWatcher #4

Merged
merged 1 commit into from

3 participants

Andrew Lunny Benjamin Lupton Mikeal Rogers
Andrew Lunny

I wasn't seeing the changed event fire when using createMonitor - not sure if there's a better reason for checking ino that I overlooked.

Benjamin Lupton

Please pull, I'm having this issue too.

Mikeal Rogers
Owner

max merged this and still had issues, i'm going to try and sit down with this today and work out a fix.

Mikeal Rogers mikeal merged commit 31e1b4d into from
Benjamin Lupton

Thanks :) Is the fix published to npm?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 28, 2011
  1. Andrew Lunny
This page is out of date. Refresh to see the latest.
Showing with 29 additions and 13 deletions.
  1. +2 −2 main.js
  2. +27 −11 test/test_monitor.js
4 main.js
View
@@ -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;
38 test/test_monitor.js
View
@@ -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);
+ })
+});
Something went wrong with that request. Please try again.