Skip to content

Commit

Permalink
Fix copyFile wrapper when retry hits EMFILE again
Browse files Browse the repository at this point in the history
PR-URL: #209
Credit: @mbargiel
Close: #209
Reviewed-by: @isaacs
  • Loading branch information
mbargiel authored and isaacs committed Jul 20, 2021
1 parent 89dc133 commit 16f8da2
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions graceful-fs.js
Expand Up @@ -178,15 +178,19 @@ function patch (fs) {
cb = flags
flags = 0
}
return fs$copyFile(src, dest, flags, function (err) {
if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
enqueue([fs$copyFile, [src, dest, flags, cb]])
else {
if (typeof cb === 'function')
cb.apply(this, arguments)
retry()
}
})
return go$copyFile(src, dest, flags, cb)

function go$copyFile (src, dest, flags, cb) {
return fs$copyFile(src, dest, flags, function (err) {
if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
enqueue([go$copyFile, [src, dest, flags, cb]])
else {
if (typeof cb === 'function')
cb.apply(this, arguments)
retry()
}
})
}
}

var fs$readdir = fs.readdir
Expand Down

0 comments on commit 16f8da2

Please sign in to comment.