pax_global_header00006660000000000000000000000064124205430770014516gustar00rootroot0000000000000052 comment=1bf3af228e646c913d786f67fdeec2f4c97be8c8 node-findit-2.2.3/000077500000000000000000000000001242054307700137225ustar00rootroot00000000000000node-findit-2.2.3/.gitignore000066400000000000000000000000161242054307700157070ustar00rootroot00000000000000/node_modules node-findit-2.2.3/.travis.yml000066400000000000000000000000601242054307700160270ustar00rootroot00000000000000language: node_js node_js: - "0.8" - "0.10" node-findit-2.2.3/LICENSE000066400000000000000000000021341242054307700147270ustar00rootroot00000000000000The MIT License (Expat) Copyright (c) 2014 Andrew Kelley Copyright (c) 2014 James Halliday Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. node-findit-2.2.3/README.md000066400000000000000000000070341242054307700152050ustar00rootroot00000000000000# findit Recursively walk directory trees. Think `/usr/bin/find`. [![build status](https://secure.travis-ci.org/andrewrk/node-findit.png)](http://travis-ci.org/andrewrk/node-findit) ## Why the fork? There is a [pull request](https://github.com/substack/node-findit/pull/34) to merge this project back into findit. The pull request fixes every open issue in findit, and it completely rewrites the code from the ground up. It also adds an additional feature regarding symlinks. I would love for substack to merge the pull request, but realistically it might not happen, and this code is objectively cleaner, more robust, and fixes several critical issues. I recommend depending on this module rather than the original findit. If the pull request is merged, however, I will add a deprecation notice to this module and happily hand the maintainer hat back to substack. # example ``` js var finder = require('findit2')(process.argv[2] || '.'); var path = require('path'); finder.on('directory', function (dir, stat, stop, linkPath) { var base = path.basename(dir); if (base === '.git' || base === 'node_modules') stop() else console.log(dir + '/') }); finder.on('file', function (file, stat, linkPath) { console.log(file); }); finder.on('link', function (link, stat) { console.log(link); }); ``` # methods ``` js var findit = require('findit2') ``` ## var finder = findit(basedir, opts) Return an event emitter `finder` that performs a recursive walk starting at `basedir`. If you set `opts.followSymlinks`, symlinks will be followed. Otherwise, a `'link'` event will fire but symlinked directories will not be walked. If `basedir` is actually a non-directory regular file, findit emits a single "file" event for it then emits "end". You can optionally specify a custom [fs](http://nodejs.org/docs/latest/api/fs.html) implementation with `opts.fs`. `opts.fs` should implement: * `opts.fs.readdir(dir, cb)` * `opts.fs.lstat(dir, cb)` * `opts.fs.readlink(dir, cb)` - optional if your stat objects from `opts.fs.lstat` never return true for `stat.isSymbolicLink()` ## finder.stop() Stop the traversal. A `"stop"` event will fire and then no more events will fire. # events ## finder.on('path', function (file, stat, linkPath) {}) For each file, directory, and symlink `file`, this event fires. If `followSymlinks` is `true`, then `linkPath` will be defined when `file` was found via a symlink. In this situation, `linkPath` is the path including the symlink; `file` is the resolved actual location on disk. ## finder.on('file', function (file, stat, linkPath) {}) For each file, this event fires. ## finder.on('directory', function (dir, stat, stop, linkPath) {}) For each directory, this event fires with the path `dir`. Your callback may call `stop()` on the first tick to tell findit to stop walking the current directory. ## finder.on('link', function (file, stat) {}) For each symlink, this event fires. ## finder.on('readlink', function (src, dst) {}) Every time a symlink is read when `opts.followSymlinks` is on, this event fires. ## finder.on('end', function () {}) When the recursive walk is complete unless `finder.stop()` was called, this event fires. ## finder.on('stop', function () {}) When `finder.stop()` is called, this event fires. ## finder.on('error', function (err) {}) Whenever there is an error, this event fires. You can choose to ignore errors or stop the traversal using `finder.stop()`. You can always get the source of the error by checking `err.path`. # install With [npm](https://npmjs.org) do: ``` npm install findit2 ``` node-findit-2.2.3/example/000077500000000000000000000000001242054307700153555ustar00rootroot00000000000000node-findit-2.2.3/example/emitter.js000066400000000000000000000006241242054307700173660ustar00rootroot00000000000000var finder = require('../')(process.argv[2] || '.'); var path = require('path'); finder.on('directory', function (dir, stat, stop) { var base = path.basename(dir); if (base === '.git' || base === 'node_modules') stop() else console.log(dir + '/') }); finder.on('file', function (file, stat) { console.log(file); }); finder.on('link', function (link, stat) { console.log(link); }); node-findit-2.2.3/index.js000066400000000000000000000060051242054307700153700ustar00rootroot00000000000000var EventEmitter = require('events').EventEmitter; var fs = require('fs'); var path = require('path'); module.exports = findit; function findit(basedir, opts) { opts = opts || {}; var followSymlinks = !!opts.followSymlinks; var myFs = opts.fs || fs; var emitter = new EventEmitter(); var stopped = false; var pending = 0; var seen = {}; emitter.stop = stop; walkPath(basedir); return emitter; function recursiveReadDir(basedir, linkPath) { pendStart(); myFs.readdir(basedir, function(err, entries) { if (stopped) return; if (err) { handleError(err, basedir); pendEnd(); return; } entries.forEach(function(entry) { var fullPath = path.join(basedir, entry); var fullLinkPath = linkPath && path.join(linkPath, entry); walkPath(fullPath, fullLinkPath); }); pendEnd(); }); } function walkPath(fullPath, linkPath) { pendStart(); myFs.lstat(fullPath, function(err, stats) { if (stopped) return; if (err) { handleError(err, fullPath); pendEnd(); return; } emitter.emit('path', fullPath, stats, linkPath); var dirStopped = false; if (stats.isDirectory()) { if (seen[fullPath]) { err = new Error("file system loop detected"); err.code = 'ELOOP'; handleError(err, fullPath); pendEnd(); return; } seen[fullPath] = true; emitter.emit('directory', fullPath, stats, stopDir, linkPath); if (!dirStopped) recursiveReadDir(fullPath, linkPath); } else if (stats.isFile()) { if (!seen[fullPath]) { seen[fullPath] = true; emitter.emit('file', fullPath, stats, linkPath); } } else if (stats.isSymbolicLink()) { emitter.emit('link', fullPath, stats, linkPath); if (followSymlinks) recursiveReadLink(fullPath); } pendEnd(); function stopDir() { dirStopped = true; } }); } function recursiveReadLink(linkPath) { pendStart(); myFs.readlink(linkPath, function(err, linkString) { if (stopped) return; if (err) { handleError(err, linkPath); pendEnd(); return; } var fullPath = path.resolve(path.dirname(linkPath), linkString); emitter.emit('readlink', linkPath, fullPath); walkPath(fullPath, linkPath); pendEnd(); }); } function stop() { if (stopped) return; stopped = true; emitter.emit('stop'); } function handleError(err, errPath) { if (!err || stopped) return; err.path = errPath; emitter.emit('error', err); } function pendStart() { pending += 1; } function pendEnd() { if (stopped) return; pending -= 1; if (pending === 0) { emitter.emit('end'); } else if (pending < 0) { // this should never happen; if this gets thrown we need to debug findit // and this stack trace will help. throw new Error("pendEnd called too many times"); } } } node-findit-2.2.3/package.json000066400000000000000000000010771242054307700162150ustar00rootroot00000000000000{ "name": "findit2", "version": "2.2.3", "description": "walk a directory tree recursively with events", "main": "index.js", "devDependencies": { "tap": "~0.4.13", "mkdirp": "~0.5.0" }, "scripts": { "test": "tap test/*.js" }, "repository": { "type": "git", "url": "http://github.com/andrewrk/node-findit.git" }, "keywords": [ "find", "walk", "directory", "recursive", "tree", "traversal" ], "author": "Andrew Kelley ", "engines": { "node": ">=0.8.22" }, "license": "MIT" } node-findit-2.2.3/test/000077500000000000000000000000001242054307700147015ustar00rootroot00000000000000node-findit-2.2.3/test/empty.js000066400000000000000000000005671242054307700164050ustar00rootroot00000000000000var mkdirp = require('mkdirp'); var test = require('tap').test; var find = require('../'); mkdirp.sync(__dirname + '/empty'); test('empty', function (t) { t.plan(1); var w = find(__dirname + '/empty'); var files = []; w.on('file', function (file) { files.push(file); }); w.on('end', function () { t.deepEqual(files, []); }); }); node-findit-2.2.3/test/err.js000066400000000000000000000004551242054307700160330ustar00rootroot00000000000000var find = require('../'); var test = require('tap').test; var path = require('path'); test('error', function (t) { t.plan(1); var finder = find(__dirname + '/does/not/exist'); finder.on('error', function (err) { t.equal(err.path, __dirname + '/does/not/exist'); }); }); node-findit-2.2.3/test/foo.js000066400000000000000000000027341242054307700160300ustar00rootroot00000000000000var find = require('../'); var test = require('tap').test; test('foo', function (t) { var finder = find(__dirname + '/foo'); var ps = {}; var paths = [] finder.on('path', function (p, stat) { paths.push(p); ps[p] = stat.isDirectory(); }); var dirs = [] finder.on('directory', function (dir) { dirs.push(dir); }); var files = [] finder.on('file', function (file) { files.push(file); }); finder.on('end', function () { var ref = { '' : true, 'a' : true, 'a/b' : true, 'a/b/c' : true, 'x' : false, 'a/y' : false, 'a/b/z' : false, 'a/b/c/w' : false, }; t.equal(Object.keys(ref).length, Object.keys(ps).length); var count = { dirs : 0, files : 0, paths : 0 }; Object.keys(ref).forEach(function (key) { var file = (__dirname + '/foo/' + key).replace(/\/$/, ''); t.equal(ref[key], ps[file]); if (ref[key]) { t.ok(dirs.indexOf(file) >= 0); count.dirs ++; } else { t.ok(files.indexOf(file) >= 0); count.files ++; } }); t.deepEqual(count.dirs, dirs.length); t.deepEqual(count.files, files.length); t.deepEqual(paths.sort(), Object.keys(ps).sort()); t.end(); }); }); node-findit-2.2.3/test/foo/000077500000000000000000000000001242054307700154645ustar00rootroot00000000000000node-findit-2.2.3/test/foo/a/000077500000000000000000000000001242054307700157045ustar00rootroot00000000000000node-findit-2.2.3/test/foo/a/b/000077500000000000000000000000001242054307700161255ustar00rootroot00000000000000node-findit-2.2.3/test/foo/a/b/c/000077500000000000000000000000001242054307700163475ustar00rootroot00000000000000node-findit-2.2.3/test/foo/a/b/c/w000066400000000000000000000000001242054307700165260ustar00rootroot00000000000000node-findit-2.2.3/test/foo/a/b/z000066400000000000000000000000001242054307700163070ustar00rootroot00000000000000node-findit-2.2.3/test/foo/a/y000066400000000000000000000000001242054307700160650ustar00rootroot00000000000000node-findit-2.2.3/test/foo/x000066400000000000000000000000001242054307700156440ustar00rootroot00000000000000node-findit-2.2.3/test/module.js000066400000000000000000000007051242054307700165260ustar00rootroot00000000000000var find = require('../'); var test = require('tap').test; test('single file', function (t) { t.plan(2); var finder = find(__filename); var files = []; finder.on('file', function (file) { t.equal(file, __filename); files.push(file); }); finder.on('directory', function (dir) { t.fail(dir); }); finder.on('end', function () { t.deepEqual(files, [ __filename ]); }); }); node-findit-2.2.3/test/stop.js000066400000000000000000000014071242054307700162260ustar00rootroot00000000000000var find = require('../'); var test = require('tap').test; var path = require('path'); test('stop', function (t) { t.plan(1); var finder = find(__dirname + '/..'); var files = []; var stopped = false; finder.on('file', function (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) { if (stopped) t.fail("directories didn't stop"); }); finder.on('end', function () { t.fail("shouldn't have ended"); }); finder.on('stop', function () { t.equal(files.length, 3); }); }); node-findit-2.2.3/test/stop/000077500000000000000000000000001242054307700156665ustar00rootroot00000000000000node-findit-2.2.3/test/stop/q/000077500000000000000000000000001242054307700161265ustar00rootroot00000000000000node-findit-2.2.3/test/stop/q/w/000077500000000000000000000000001242054307700163745ustar00rootroot00000000000000node-findit-2.2.3/test/stop/q/w/c000066400000000000000000000000001242054307700165270ustar00rootroot00000000000000node-findit-2.2.3/test/stop/q/w/d000066400000000000000000000000001242054307700165300ustar00rootroot00000000000000node-findit-2.2.3/test/stop/q/x000066400000000000000000000000001242054307700163060ustar00rootroot00000000000000node-findit-2.2.3/test/stop/q/y000066400000000000000000000000001242054307700163070ustar00rootroot00000000000000node-findit-2.2.3/test/stop/q/z/000077500000000000000000000000001242054307700163775ustar00rootroot00000000000000node-findit-2.2.3/test/stop/q/z/m000066400000000000000000000000001242054307700165440ustar00rootroot00000000000000node-findit-2.2.3/test/stop/q/z/n000066400000000000000000000000001242054307700165450ustar00rootroot00000000000000node-findit-2.2.3/test/stop/r/000077500000000000000000000000001242054307700161275ustar00rootroot00000000000000node-findit-2.2.3/test/stop/r/a000066400000000000000000000000001242054307700162600ustar00rootroot00000000000000node-findit-2.2.3/test/stop/r/b000066400000000000000000000000001242054307700162610ustar00rootroot00000000000000node-findit-2.2.3/test/stop/r/c/000077500000000000000000000000001242054307700163515ustar00rootroot00000000000000node-findit-2.2.3/test/stop/r/c/f/000077500000000000000000000000001242054307700165765ustar00rootroot00000000000000node-findit-2.2.3/test/stop/r/c/f/h000066400000000000000000000000001242054307700167360ustar00rootroot00000000000000node-findit-2.2.3/test/stop/r/c/g/000077500000000000000000000000001242054307700165775ustar00rootroot00000000000000node-findit-2.2.3/test/stop/r/c/g/i000066400000000000000000000000001242054307700167400ustar00rootroot00000000000000node-findit-2.2.3/test/symlinks.js000066400000000000000000000047431242054307700171200ustar00rootroot00000000000000var test = require('tap').test; var path = require('path'); var findit = require('../'); function helper(t, dir, options, callback) { var symlinks = []; var files = []; var dirs = []; var errors = []; var finder = findit(dir, options); finder.on('link', function (link, stat) { t.ok(stat.isSymbolicLink()); symlinks.push(path.basename(link)); }); finder.on('file', function (file, stat) { t.ok(stat.isFile()); files.push(path.basename(file)); }); finder.on('directory', function (dir, stat) { t.ok(stat.isDirectory()); dirs.push(path.basename(dir)); }); finder.on('error', function (err) { errors.push(err); }); finder.on('end', function () { symlinks.sort(); files.sort(); dirs.sort(); callback({ errors: errors, symlinks: symlinks, files: files, dirs: dirs }); }); } test('links', function (t) { helper(t, __dirname + '/symlinks/dir1', { followSymlinks: false }, done); function done (data) { t.deepEqual(data.errors, []); t.deepEqual(data.symlinks, [ 'dangling-symlink', 'link-to-dir2', 'link-to-file' ]); t.deepEqual(data.files, [ 'file1' ]); t.deepEqual(data.dirs, [ 'dir1' ]); t.end(); } }); test('follow links', function (t) { helper(t, __dirname + '/symlinks/dir1', { followSymlinks: true }, done); function done (data) { t.equal(data.errors.length, 2); t.equal( data.errors[0].path, __dirname + '/symlinks/dir1/does-not-exist' ); t.equal( data.errors[1].path, __dirname + '/symlinks/dir1' ); t.deepEqual(data.symlinks, [ 'cyclic-link-to-dir1', 'dangling-symlink', 'link-to-dir2', 'link-to-file' ]); t.deepEqual(data.files, ['file', 'file1', 'file2']); t.deepEqual(data.dirs, [ 'dir1', 'dir2' ]); t.end(); } }); test('parent links', function (t) { helper(t, __dirname + '/symlinks', { followSymlinks: true }, done); function done (data) { t.deepEqual(data.symlinks, [ 'cyclic-link-to-dir1', 'dangling-symlink', 'link-to-dir2', 'link-to-file' ]); t.deepEqual(data.files, ['file', 'file1', 'file2']); t.deepEqual(data.dirs, [ 'dir1', 'dir2', 'symlinks' ]); t.end(); } }); node-findit-2.2.3/test/symlinks/000077500000000000000000000000001242054307700165525ustar00rootroot00000000000000node-findit-2.2.3/test/symlinks/dir1/000077500000000000000000000000001242054307700174115ustar00rootroot00000000000000node-findit-2.2.3/test/symlinks/dir1/dangling-symlink000077700000000000000000000000001242054307700254032does-not-existustar00rootroot00000000000000node-findit-2.2.3/test/symlinks/dir1/file1000066400000000000000000000000001242054307700203220ustar00rootroot00000000000000node-findit-2.2.3/test/symlinks/dir1/link-to-dir2000077700000000000000000000000001242054307700225402../dir2ustar00rootroot00000000000000node-findit-2.2.3/test/symlinks/dir1/link-to-file000077700000000000000000000000001242054307700226762../fileustar00rootroot00000000000000node-findit-2.2.3/test/symlinks/dir2/000077500000000000000000000000001242054307700174125ustar00rootroot00000000000000node-findit-2.2.3/test/symlinks/dir2/cyclic-link-to-dir1000077700000000000000000000000001242054307700240032../dir1ustar00rootroot00000000000000node-findit-2.2.3/test/symlinks/dir2/file2000066400000000000000000000000001242054307700203240ustar00rootroot00000000000000node-findit-2.2.3/test/symlinks/file000066400000000000000000000000001242054307700174020ustar00rootroot00000000000000