From 06d0104f56631a80472454e7ba40e7b4c15e710b Mon Sep 17 00:00:00 2001 From: suguanyang Date: Wed, 5 Jul 2023 14:16:26 +0800 Subject: [PATCH] feat: enqueue rm when EMFILE --- graceful-fs.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/graceful-fs.js b/graceful-fs.js index 8d5b89e..e06e082 100644 --- a/graceful-fs.js +++ b/graceful-fs.js @@ -364,6 +364,26 @@ function patch (fs) { }) } } + + var fs$rm = fs.rm + fs.rm = rm + function rm(path, options, cb) { + if (typeof options === 'function') + cb = options, options = null + + return go$rm(path, options, cb) + + function go$rm (path, options, cb, startTime) { + return fs$rm(path, options, function (err, fd) { + if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) + enqueue([go$rm, [path, options, cb], err, startTime || Date.now(), Date.now()]) + else { + if (typeof cb === 'function') + cb.apply(this, arguments) + } + }) + } + } return fs }