From 466cda05484c612769effb8c61a9a8ea8379bef2 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Mon, 10 Sep 2018 09:57:15 -0400 Subject: fs: ensure readdir() callback is only called once This commit ensures that the readdir() callback can only be called once when the withFileTypes parameter is supplied. PR-URL: https://github.com/nodejs/node/pull/22793 Fixes: https://github.com/nodejs/node/issues/22778 Reviewed-By: Bryan English Reviewed-By: Anatoli Papirovski Reviewed-By: Minwoo Jung --- lib/internal/util.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/internal/util.js') diff --git a/lib/internal/util.js b/lib/internal/util.js index 43b9974068..5cb1b281ba 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -365,6 +365,15 @@ function isInsideNodeModules() { return false; } +function once(callback) { + let called = false; + return function(...args) { + if (called) return; + called = true; + callback(...args); + }; +} + module.exports = { assertCrypto, cachedResult, @@ -381,6 +390,7 @@ module.exports = { join, normalizeEncoding, objectToString, + once, promisify, spliceOne, removeColors, -- cgit v1.2.3