Skip to content

Commit 1cc1135

Browse files
committed
fix: fs.readdir() on ancient nodes that don't know about options
Fix: #218
1 parent e973238 commit 1cc1135

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

graceful-fs.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)