diff --git a/lib/fs.js b/lib/fs.js index daeb20e747e..653369b1d90 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1225,7 +1225,7 @@ function StatWatcher() { this._handle.onchange = function(current, previous, newStatus) { if (oldStatus === -1 && - newStatus === -1 && + newStatus < 0 && current.nlink === previous.nlink) return; oldStatus = newStatus; diff --git a/test/simple/test-fs-watchFile.js b/test/simple/test-fs-watchFile.js new file mode 100644 index 00000000000..8b2ac087b7e --- /dev/null +++ b/test/simple/test-fs-watchFile.js @@ -0,0 +1,15 @@ +var assert = require('assert'); +var fs = require('fs'); + +function callbackFail(){ + assert(false, "Callback should not be called for non-existant files") +} + +//regression test for #25345 +var filename = 'doesNotExist.txt'; +assert(!fs.existsSync(filename), "dummy file exists"); +fs.watchFile(filename, callbackFail); + +setTimeout(function() { + process.exit() +}, 5000);