filewatcher
Advanced tools
Comparing version 2.0.3 to 2.1.0
32
index.js
var fs = require('fs') | ||
, util = require('util') | ||
, events = require('events') | ||
, EventEmitter = events.EventEmitter | ||
var util = require('util') | ||
var events = require('events') | ||
var EventEmitter = events.EventEmitter | ||
var outOfFileHandles = false | ||
module.exports = function(opts) { | ||
@@ -27,2 +29,5 @@ return new FileWatcher(opts) | ||
// don't add files after we ran out of file handles | ||
if (outOfFileHandles && !this.polling) return | ||
// ignore files that don't exist or are already watched | ||
@@ -37,2 +42,3 @@ if (this.watchers[file] || !fs.existsSync(file)) return | ||
fs.stat(file, function(err, stat) { | ||
if (!self.watchers[file]) return | ||
@@ -47,4 +53,6 @@ | ||
if (!stat) return self.emit('change', file, { deleted: true }) | ||
if (stat.isDirectory() || stat.mtime > mtime) { | ||
if (!stat) { | ||
self.emit('change', file, { deleted: true }) | ||
} | ||
else if (stat.isDirectory() || stat.mtime > mtime) { | ||
mtime = stat.mtime | ||
@@ -67,5 +75,13 @@ self.emit('change', file, stat) | ||
catch (err) { | ||
// emit fallback event if we ran out of file handles | ||
if (err.code == 'EMFILE') this.emit('fallback', this.poll()) | ||
else this.emit('error', err) | ||
if (err.code == 'EMFILE') { | ||
if (this.opts.fallback !== false) { | ||
// emit fallback event if we ran out of file handles | ||
var count = this.poll() | ||
this.add(file) | ||
this.emit('fallback', count) | ||
return | ||
} | ||
outOfFileHandles = true | ||
} | ||
this.emit('error', err) | ||
} | ||
@@ -72,0 +88,0 @@ } |
{ | ||
"name": "filewatcher", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"description": "Wrapper around fs.watch with fallback to fs.watchFile", | ||
@@ -19,11 +19,8 @@ "author": "Felix Gnass", | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "ulimit -n 100 && ULIMIT=`ulimit -n` node test" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.14.0", | ||
"should": "~2.1.0", | ||
"rimraf": "~2.2.2", | ||
"posix": "~1.0.3" | ||
}, | ||
"dependencies": {} | ||
"tap": "^0.5.0" | ||
} | ||
} |
@@ -44,3 +44,3 @@ # filewatcher | ||
Copyright (c) 2013 Felix Gnass | ||
Copyright (c) 2013-2015 Felix Gnass | ||
@@ -47,0 +47,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5973
2
103