From 18c3017dbfe84b6bf0274a4c72bad7f4d3d2079a Mon Sep 17 00:00:00 2001 From: Aleh Zasypkin Date: Wed, 16 Feb 2022 12:34:41 +0100 Subject: [PATCH] =?UTF-8?q?Rollback=20graceful-fs=20merge=20due=20to=20inc?= =?UTF-8?q?ompatible=20patch=20releases=20=F0=9F=A4=A6.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/kbn-pm/dist/index.js | 181 +++++++++------------------------- yarn.lock | 12 ++- 2 files changed, 59 insertions(+), 134 deletions(-) diff --git a/packages/kbn-pm/dist/index.js b/packages/kbn-pm/dist/index.js index 09edff0cab67fc..756246cc251a9b 100644 --- a/packages/kbn-pm/dist/index.js +++ b/packages/kbn-pm/dist/index.js @@ -17071,7 +17071,7 @@ if (!fs[gracefulQueue]) { return fs$close.call(fs, fd, function (err) { // This function uses the graceful-fs shared queue if (!err) { - resetQueue() + retry() } if (typeof cb === 'function') @@ -17089,7 +17089,7 @@ if (!fs[gracefulQueue]) { function closeSync (fd) { // This function uses the graceful-fs shared queue fs$closeSync.apply(fs, arguments) - resetQueue() + retry() } Object.defineProperty(closeSync, previousSymbol, { @@ -17131,13 +17131,14 @@ function patch (fs) { return go$readFile(path, options, cb) - function go$readFile (path, options, cb, startTime) { + function go$readFile (path, options, cb) { return fs$readFile(path, options, function (err) { if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) - enqueue([go$readFile, [path, options, cb], err, startTime || Date.now(), Date.now()]) + enqueue([go$readFile, [path, options, cb]]) else { if (typeof cb === 'function') cb.apply(this, arguments) + retry() } }) } @@ -17151,13 +17152,14 @@ function patch (fs) { return go$writeFile(path, data, options, cb) - function go$writeFile (path, data, options, cb, startTime) { + function go$writeFile (path, data, options, cb) { return fs$writeFile(path, data, options, function (err) { if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) - enqueue([go$writeFile, [path, data, options, cb], err, startTime || Date.now(), Date.now()]) + enqueue([go$writeFile, [path, data, options, cb]]) else { if (typeof cb === 'function') cb.apply(this, arguments) + retry() } }) } @@ -17172,35 +17174,14 @@ function patch (fs) { return go$appendFile(path, data, options, cb) - function go$appendFile (path, data, options, cb, startTime) { + function go$appendFile (path, data, options, cb) { return fs$appendFile(path, data, options, function (err) { if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) - enqueue([go$appendFile, [path, data, options, cb], err, startTime || Date.now(), Date.now()]) - else { - if (typeof cb === 'function') - cb.apply(this, arguments) - } - }) - } - } - - var fs$copyFile = fs.copyFile - if (fs$copyFile) - fs.copyFile = copyFile - function copyFile (src, dest, flags, cb) { - if (typeof flags === 'function') { - cb = flags - flags = 0 - } - return go$copyFile(src, dest, flags, cb) - - function go$copyFile (src, dest, flags, cb, startTime) { - return fs$copyFile(src, dest, flags, function (err) { - if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) - enqueue([go$copyFile, [src, dest, flags, cb], err, startTime || Date.now(), Date.now()]) + enqueue([go$appendFile, [path, data, options, cb]]) else { if (typeof cb === 'function') cb.apply(this, arguments) + retry() } }) } @@ -17209,26 +17190,35 @@ function patch (fs) { var fs$readdir = fs.readdir fs.readdir = readdir function readdir (path, options, cb) { - if (typeof options === 'function') - cb = options, options = null + var args = [path] + if (typeof options !== 'function') { + args.push(options) + } else { + cb = options + } + args.push(go$readdir$cb) - return go$readdir(path, options, cb) + return go$readdir(args) - function go$readdir (path, options, cb, startTime) { - return fs$readdir(path, options, function (err, files) { - if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) - enqueue([go$readdir, [path, options, cb], err, startTime || Date.now(), Date.now()]) - else { - if (files && files.sort) - files.sort() + function go$readdir$cb (err, files) { + if (files && files.sort) + files.sort() - if (typeof cb === 'function') - cb.call(this, err, files) - } - }) + if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) + enqueue([go$readdir, [args]]) + + else { + if (typeof cb === 'function') + cb.apply(this, arguments) + retry() + } } } + function go$readdir (args) { + return fs$readdir.apply(fs, args) + } + if (process.version.substr(0, 4) === 'v0.8') { var legStreams = legacy(fs) ReadStream = legStreams.ReadStream @@ -17351,13 +17341,14 @@ function patch (fs) { return go$open(path, flags, mode, cb) - function go$open (path, flags, mode, cb, startTime) { + function go$open (path, flags, mode, cb) { return fs$open(path, flags, mode, function (err, fd) { if (err && (err.code === 'EMFILE' || err.code === 'ENFILE')) - enqueue([go$open, [path, flags, mode, cb], err, startTime || Date.now(), Date.now()]) + enqueue([go$open, [path, flags, mode, cb]]) else { if (typeof cb === 'function') cb.apply(this, arguments) + retry() } }) } @@ -17369,79 +17360,13 @@ function patch (fs) { function enqueue (elem) { debug('ENQUEUE', elem[0].name, elem[1]) fs[gracefulQueue].push(elem) - retry() -} - -// keep track of the timeout between retry() calls -var retryTimer - -// reset the startTime and lastTime to now -// this resets the start of the 60 second overall timeout as well as the -// delay between attempts so that we'll retry these jobs sooner -function resetQueue () { - var now = Date.now() - for (var i = 0; i < fs[gracefulQueue].length; ++i) { - // entries that are only a length of 2 are from an older version, don't - // bother modifying those since they'll be retried anyway. - if (fs[gracefulQueue][i].length > 2) { - fs[gracefulQueue][i][3] = now // startTime - fs[gracefulQueue][i][4] = now // lastTime - } - } - // call retry to make sure we're actively processing the queue - retry() } function retry () { - // clear the timer and remove it to help prevent unintended concurrency - clearTimeout(retryTimer) - retryTimer = undefined - - if (fs[gracefulQueue].length === 0) - return - var elem = fs[gracefulQueue].shift() - var fn = elem[0] - var args = elem[1] - // these items may be unset if they were added by an older graceful-fs - var err = elem[2] - var startTime = elem[3] - var lastTime = elem[4] - - // if we don't have a startTime we have no way of knowing if we've waited - // long enough, so go ahead and retry this item now - if (startTime === undefined) { - debug('RETRY', fn.name, args) - fn.apply(null, args) - } else if (Date.now() - startTime >= 60000) { - // it's been more than 60 seconds total, bail now - debug('TIMEOUT', fn.name, args) - var cb = args.pop() - if (typeof cb === 'function') - cb.call(null, err) - } else { - // the amount of time between the last attempt and right now - var sinceAttempt = Date.now() - lastTime - // the amount of time between when we first tried, and when we last tried - // rounded up to at least 1 - var sinceStart = Math.max(lastTime - startTime, 1) - // backoff. wait longer than the total time we've been retrying, but only - // up to a maximum of 100ms - var desiredDelay = Math.min(sinceStart * 1.2, 100) - // it's been long enough since the last retry, do it again - if (sinceAttempt >= desiredDelay) { - debug('RETRY', fn.name, args) - fn.apply(null, args.concat([startTime])) - } else { - // if we can't do this job yet, push it to the end of the queue - // and let the next iteration check again - fs[gracefulQueue].push(elem) - } - } - - // schedule our next run if one isn't already scheduled - if (retryTimer === undefined) { - retryTimer = setTimeout(retry, 0) + if (elem) { + debug('RETRY', elem[0].name, elem[1]) + elem[0].apply(null, elem[1]) } } @@ -17466,14 +17391,10 @@ try { process.cwd() } catch (er) {} -// This check is needed until node.js 12 is required -if (typeof process.chdir === 'function') { - var chdir = process.chdir - process.chdir = function (d) { - cwd = null - chdir.call(process, d) - } - if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, chdir) +var chdir = process.chdir +process.chdir = function(d) { + cwd = null + chdir.call(process, d) } module.exports = patch @@ -17588,7 +17509,7 @@ function patch (fs) { } // This ensures `util.promisify` works as it does for native `fs.read`. - if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read) + read.__proto__ = fs$read return read })(fs.read) @@ -17762,10 +17683,8 @@ function patch (fs) { return function (target, options) { var stats = options ? orig.call(fs, target, options) : orig.call(fs, target) - if (stats) { - if (stats.uid < 0) stats.uid += 0x100000000 - if (stats.gid < 0) stats.gid += 0x100000000 - } + if (stats.uid < 0) stats.uid += 0x100000000 + if (stats.gid < 0) stats.gid += 0x100000000 return stats; } } @@ -17939,16 +17858,12 @@ function legacy (fs) { module.exports = clone -var getPrototypeOf = Object.getPrototypeOf || function (obj) { - return obj.__proto__ -} - function clone (obj) { if (obj === null || typeof obj !== 'object') return obj if (obj instanceof Object) - var copy = { __proto__: getPrototypeOf(obj) } + var copy = { __proto__: obj.__proto__ } else var copy = Object.create(null) diff --git a/yarn.lock b/yarn.lock index d9c94102e18457..904f05f770f7ee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16612,7 +16612,17 @@ got@^9.6.0: to-readable-stream "^1.0.0" url-parse-lax "^3.0.0" -graceful-fs@4.X, graceful-fs@^4.0.0, graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9, graceful-fs@^4.2.0, graceful-fs@^4.2.2, graceful-fs@^4.2.3, graceful-fs@^4.2.4, graceful-fs@^4.2.6, graceful-fs@^4.2.9: +graceful-fs@4.X, graceful-fs@^4.0.0, graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9, graceful-fs@^4.2.0, graceful-fs@^4.2.2, graceful-fs@^4.2.4: + version "4.2.4" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb" + integrity sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw== + +graceful-fs@^4.2.3, graceful-fs@^4.2.6: + version "4.2.6" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.6.tgz#ff040b2b0853b23c3d31027523706f1885d76bee" + integrity sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ== + +graceful-fs@^4.2.9: version "4.2.9" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.9.tgz#041b05df45755e587a24942279b9d113146e1c96" integrity sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==