Comparing version 1.0.1 to 1.1.0
10
index.js
@@ -12,2 +12,6 @@ var EventEmitter = require('events').EventEmitter; | ||
emitter = new EventEmitter; | ||
emitter.stop = function () { | ||
emitter._stopped = true; | ||
emitter.emit('stop'); | ||
}; | ||
emitter._pending = 0; | ||
@@ -28,2 +32,3 @@ emitter._seen = {}; | ||
else fs.lstat(dir, function onstat (err, stat) { | ||
if (emitter._stopped) return; | ||
if (err) return finish(); | ||
@@ -35,2 +40,3 @@ emitter._seen[stat.ino || dir] = true; | ||
fs.readlink(dir, function (err, rfile) { | ||
if (emitter._stopped) return; | ||
if (err) return finish(); | ||
@@ -75,2 +81,3 @@ var file_ = path.resolve(dir, rfile); | ||
function onreaddir (err, files) { | ||
if (emitter._stopped) return; | ||
emitter._pending --; | ||
@@ -84,2 +91,3 @@ if (err) return check(); | ||
fs.lstat(file, function (err, stat) { | ||
if (emitter._stopped) return; | ||
if (err) check() | ||
@@ -104,2 +112,3 @@ else onstat(file, stat) | ||
fs.readlink(file, function (err, rfile) { | ||
if (emitter._stopped) return; | ||
if (err) return check(); | ||
@@ -110,2 +119,3 @@ var file_ = path.resolve(path.dirname(file), rfile); | ||
fs.lstat(file_, function (err, stat_) { | ||
if (emitter._stopped) return; | ||
if (err) return check(); | ||
@@ -112,0 +122,0 @@ |
{ | ||
"name": "findit", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "walk a directory tree recursively with events", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,24 +8,27 @@ var find = require('../'); | ||
var finder = find(__dirname + '/stop'); | ||
var finder = find(__dirname + '/..'); | ||
var files = []; | ||
var stopped = false; | ||
finder.on('file', function (file) { | ||
files.push(path.relative(__dirname, file)); | ||
files.push(file); | ||
if (files.length === 3) { | ||
finder.stop(); | ||
stopped = true; | ||
} | ||
else if (stopped) { | ||
t.fail("files didn't stop"); | ||
} | ||
}); | ||
finder.on('directory', function (dir, stat, stop) { | ||
var d = path.basename(dir); | ||
if (d === 'c') stop(); | ||
else if (d === 'w') stop(); | ||
if (stopped) t.fail("directories didn't stop"); | ||
}); | ||
finder.on('end', function () { | ||
t.deepEqual(files.sort(), [ | ||
'stop/q/x', | ||
'stop/q/y', | ||
'stop/q/z/m', | ||
'stop/q/z/n', | ||
'stop/r/a', | ||
'stop/r/b' | ||
]); | ||
t.fail("shouldn't have ended"); | ||
}); | ||
finder.on('stop', function () { | ||
t.equal(files.length, 3); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
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
13213
290
95