joyent/node — Issue #2093: fs.watch produces no error even though target does not exist
Author: TrevorBurnham
Created: 2011-11-13 23:07:32+00:00
State: open

The following code produces no output (tested on Node 0.6.1 under OS X):

var fs = require('fs');
fs.mkdirSync('foo');
fs.watch('foo', function(event) {
console.log(event);
});
fs.rmdirSync('foo');

This code, on the other hand, displays a `'change'` event:

var fs = require('fs');
fs.mkdirSync('foo');
fs.watch('foo', function(event) {
console.log(event);
});
process.nextTick(function(){
fs.rmdirSync('foo');
});

And this code causes `fs.watch` to immediately throw an error:

var fs = require('fs');
fs.mkdirSync('foo');
fs.rmdirSync('foo');
fs.watch('foo', function(event) {
console.log(event);
});

What's going on here? It appears that there's a certain window of time when a target is being unlinked during which `fs.watch` will neither detect the unlink event nor complain that the target does not exist.