@@ -191,24 +191,43 @@ function patch (fs) {
191191
192192 var fs$readdir = fs . readdir
193193 fs . readdir = readdir
194+ var noReaddirOptionVersions = / ^ v [ 0 - 5 ] \. /
194195 function readdir ( path , options , cb ) {
195196 if ( typeof options === 'function' )
196197 cb = options , options = null
197198
199+ var go$readdir = noReaddirOptionVersions . test ( process . version )
200+ ? function go$readdir ( path , options , cb , startTime ) {
201+ return fs$readdir ( path , fs$readdirCallback (
202+ path , options , cb , startTime
203+ ) )
204+ }
205+ : function go$readdir ( path , options , cb , startTime ) {
206+ return fs$readdir ( path , options , fs$readdirCallback (
207+ path , options , cb , startTime
208+ ) )
209+ }
210+
198211 return go$readdir ( path , options , cb )
199212
200- function go$readdir ( path , options , cb , startTime ) {
201- return fs$readdir ( path , options , function ( err , files ) {
213+ function fs$readdirCallback ( path , options , cb , startTime ) {
214+ return function ( err , files ) {
202215 if ( err && ( err . code === 'EMFILE' || err . code === 'ENFILE' ) )
203- enqueue ( [ go$readdir , [ path , options , cb ] , err , startTime || Date . now ( ) , Date . now ( ) ] )
216+ enqueue ( [
217+ go$readdir ,
218+ [ path , options , cb ] ,
219+ err ,
220+ startTime || Date . now ( ) ,
221+ Date . now ( )
222+ ] )
204223 else {
205224 if ( files && files . sort )
206225 files . sort ( )
207226
208227 if ( typeof cb === 'function' )
209228 cb . call ( this , err , files )
210229 }
211- } )
230+ }
212231 }
213232 }
214233
0 commit comments