added followLinks option for realz

This commit is contained in:
AJ ONeal 2013-06-22 22:56:13 -07:00
parent a26de5a66c
commit ec07897228
2 changed files with 44 additions and 8 deletions

15
.jshintrc Normal file
View File

@ -0,0 +1,15 @@
{ "es5": true
, "node": true
, "browser": true
, "jquery": true
, "onevar": true
, "laxcomma": true
, "laxbreak": true
, "eqeqeq": true
, "immed": true
, "undef": true
, "unused": true
, "latedef": true
}

View File

@ -1,4 +1,3 @@
/*jshint strict:true node:true es5:true onevar:true laxcomma:true laxbreak:true*/
// Adapted from work by jorge@jorgechamorro.com on 2010-11-25
(function () {
"use strict";
@ -31,6 +30,9 @@
var me = this
;
options = options || {};
me._wStat = options.followLinks && 'stat' || 'lstat';
me._wStatSync = me._wStat + 'Sync';
me._wsync = sync;
me._wq = [];
me._wqueue = [me._wq];
@ -39,15 +41,28 @@
me._wcurpath = pathname;
if (me._wsync) {
console.log('_walkSync');
me._wWalk = me._wWalkSync;
} else {
console.log('_walkASync');
me._wWalk = me._wWalkAsync;
}
// TODO just one little anony won't hurt...
process.nextTick(function () {
me._wWalk();
options.listeners = options.listeners || {};
Object.keys(options.listeners).forEach(function (event) {
var callbacks = options.listeners[event]
;
if ('function' === typeof callbacks) {
callbacks = [callbacks];
}
callbacks.forEach(function (callback) {
me.on(event, callback);
});
});
me._wWalk();
}
// Inherits must come before prototype additions
@ -86,14 +101,14 @@
if (!me._wsync) {
// TODO how to remove this anony?
fs.lstat(statPath, function (err, stat) {
fs[me._wStat](statPath, function (err, stat) {
me._wLstatHandler(err, stat);
});
return;
}
try {
me._wLstatHandler(null, fs.lstatSync(statPath));
me._wLstatHandler(null, fs[me._wStatSync](statPath));
} catch(e) {
me._wLstatHandler(e);
}
@ -159,7 +174,7 @@
me._wfirstrun = false;
// TODO how to remove this anony?
fs.lstat(me._wcurpath, function (e, stat) {
fs[me._wStat](me._wcurpath, function (e, stat) {
if (stat) {
files = [me._wcurpath.replace(/.*\//, '')];
@ -170,6 +185,7 @@
});
};
Walker.prototype._wWalkSync = function () {
console.log('walkSync');
var err
, files
, me = this
@ -184,6 +200,7 @@
me._wReaddirHandler(err, files);
};
Walker.prototype._wWalkAsync = function () {
console.log('walkAsync');
var me = this
;
@ -209,7 +226,11 @@
me._wq = me._wqueue[me._wqueue.length - 1];
return this._wNext();
}
me.emit('end');
// To not break compatibility
//process.nextTick(function () {
me.emit('end');
//});
};
Walker.prototype._wJoinPath = function (v, i, o) {
var me = this