Permalink
Browse files

take out symlink events for now

  • Loading branch information...
1 parent c2a84c6 commit 29070fd7eacc420d03b9c5001d083f9eec243f35 @substack substack committed Jun 17, 2011
Showing with 30 additions and 30 deletions.
  1. +6 −7 README.markdown
  2. +12 −13 index.js
  3. +1 −1 package.json
  4. +11 −9 test/cycle.js
View
13 README.markdown
@@ -53,6 +53,10 @@ documented below in "events".
If `basedir` is actually a non-directory regular file, findit emits a single
"file" event for it then emits "end".
+Findit uses `fs.stat()` so symlinks are traversed automatically. Findit won't
+traverse an inode that it has seen before so directories can have symlink cycles
+and findit won't blow up.
+
Returns an EventEmitter. See "events".
findSync(basedir)
@@ -67,17 +71,12 @@ events
file: [ file, stat ]
--------------------
-Emitted for just files which are not directories (including symlinks).
+Emitted for just files which are not directories.
directory : [ directory, stat ]
-------------------------------
-Emitted for directories (including symlinks).
-
-link : [ file, stat ]
----------------------
-
-Emitted for symlinks. A "file" or "directory" event is also emitted.
+Emitted for directories.
path : [ file, stat ]
---------------------
View
25 index.js
@@ -23,26 +23,25 @@ function find (base, cb) {
.seqEach(function (file) {
var stat = this.vars[file];
if (cb) cb(file, stat);
- em.emit('path', file, stat);
-
- if (stat.isSymbolicLink()) {
- em.emit('link', file, stat);
- }
if (inodes[stat.ino]) {
// already seen this inode, probably a recursive symlink
this(null);
}
- else if (stat.isDirectory()) {
- em.emit('directory', file, stat);
- finder(file, this);
- }
else {
- em.emit('file', file, stat);
- this(null);
+ em.emit('path', file, stat);
+
+ if (stat.isDirectory()) {
+ em.emit('directory', file, stat);
+ finder(file, this);
+ }
+ else {
+ em.emit('file', file, stat);
+ this(null);
+ }
+
+ inodes[stat.ino] = true;
}
-
- inodes[stat.ino] = true;
})
.seq(f.bind({}, null))
.catch(em.emit.bind(em, 'error'))
View
2 package.json
@@ -1,6 +1,6 @@
{
"name" : "findit",
- "version" : "0.0.5",
+ "version" : "0.1.0",
"description" : "Walk a directory tree.",
"main" : "./index.js",
"dependencies" : {
View
20 test/cycle.js
@@ -1,21 +1,21 @@
var assert = require('assert');
-var findit = require('findit');
+var findit = require('../');
var Hash = require('hashish');
exports.cycle = function () {
var find = findit.find(__dirname + '/cycle');
- var found = { directory : [], link : [], file : [] };
+ var found = { directory : [], file : [], path : [] };
- find.on('directory', function (dir, stat) {
+ find.on('directory', function (dir) {
found.directory.push(dir);
});
- find.on('link', function () {
- found.link.push(dir);
+ find.on('file', function (file) {
+ found.file.push(file);
});
- find.on('file', function (file) {
- found.file.push(dir);
+ find.on('path', function (file) {
+ found.path.push(file);
});
var to = setTimeout(function () {
@@ -26,14 +26,16 @@ exports.cycle = function () {
clearTimeout(to);
var dirs = Hash.map({
directory : [ 'meep', 'meep/moop' ],
- link : [ 'meep/moop' ],
- file : []
+ file : [],
+ path : [ 'meep', 'meep/moop' ]
}, function (x) {
return x.map(function (dir) {
return __dirname + '/cycle/' + dir
})
});
assert.deepEqual(dirs.directory, found.directory);
+ assert.deepEqual(dirs.file, found.file);
+ assert.deepEqual(dirs.path, found.path);
});
};

0 comments on commit 29070fd

Please sign in to comment.