|
| 1 | +diff --git a/graceful-fs.js b/graceful-fs.js |
| 2 | +index 8d5b89e4fa7fdbaebf58556cc044d2a912bce5de..7c34dcf6400831d186c8d6eb5726224bf6f3b1a0 100644 |
| 3 | +--- a/graceful-fs.js |
| 4 | ++++ b/graceful-fs.js |
| 5 | +@@ -5,28 +5,10 @@ var clone = require('./clone.js') |
| 6 | + |
| 7 | + var util = require('util') |
| 8 | + |
| 9 | +-/* istanbul ignore next - node 0.x polyfill */ |
| 10 | +-var gracefulQueue |
| 11 | +-var previousSymbol |
| 12 | +- |
| 13 | +-/* istanbul ignore else - node 0.x polyfill */ |
| 14 | +-if (typeof Symbol === 'function' && typeof Symbol.for === 'function') { |
| 15 | +- gracefulQueue = Symbol.for('graceful-fs.queue') |
| 16 | +- // This is used in testing by future versions |
| 17 | +- previousSymbol = Symbol.for('graceful-fs.previous') |
| 18 | +-} else { |
| 19 | +- gracefulQueue = '___graceful-fs.queue' |
| 20 | +- previousSymbol = '___graceful-fs.previous' |
| 21 | +-} |
| 22 | +- |
| 23 | + function noop () {} |
| 24 | + |
| 25 | + function publishQueue(context, queue) { |
| 26 | +- Object.defineProperty(context, gracefulQueue, { |
| 27 | +- get: function() { |
| 28 | +- return queue |
| 29 | +- } |
| 30 | +- }) |
| 31 | ++ context['___graceful-fs_queue'] = queue |
| 32 | + } |
| 33 | + |
| 34 | + var debug = noop |
| 35 | +@@ -40,9 +22,9 @@ else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || '')) |
| 36 | + } |
| 37 | + |
| 38 | + // Once time initialization |
| 39 | +-if (!fs[gracefulQueue]) { |
| 40 | ++if (!fs['___graceful-fs_queue']) { |
| 41 | + // This queue can be shared by multiple loaded instances |
| 42 | +- var queue = global[gracefulQueue] || [] |
| 43 | ++ var queue = global['___graceful-fs_queue'] || [] |
| 44 | + publishQueue(fs, queue) |
| 45 | + |
| 46 | + // Patch fs.close/closeSync to shared queue version, because we need |
| 47 | +@@ -62,7 +44,7 @@ if (!fs[gracefulQueue]) { |
| 48 | + }) |
| 49 | + } |
| 50 | + |
| 51 | +- Object.defineProperty(close, previousSymbol, { |
| 52 | ++ Object.defineProperty(close, '___graceful-fs_previous', { |
| 53 | + value: fs$close |
| 54 | + }) |
| 55 | + return close |
| 56 | +@@ -75,7 +57,7 @@ if (!fs[gracefulQueue]) { |
| 57 | + resetQueue() |
| 58 | + } |
| 59 | + |
| 60 | +- Object.defineProperty(closeSync, previousSymbol, { |
| 61 | ++ Object.defineProperty(closeSync, '___graceful-fs_previous', { |
| 62 | + value: fs$closeSync |
| 63 | + }) |
| 64 | + return closeSync |
| 65 | +@@ -83,14 +65,14 @@ if (!fs[gracefulQueue]) { |
| 66 | + |
| 67 | + if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || '')) { |
| 68 | + process.on('exit', function() { |
| 69 | +- debug(fs[gracefulQueue]) |
| 70 | +- require('assert').equal(fs[gracefulQueue].length, 0) |
| 71 | ++ debug(fs['___graceful-fs_queue']) |
| 72 | ++ require('assert').equal(fs['___graceful-fs_queue'].length, 0) |
| 73 | + }) |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | +-if (!global[gracefulQueue]) { |
| 78 | +- publishQueue(global, fs[gracefulQueue]); |
| 79 | ++if (!global['___graceful-fs_queue']) { |
| 80 | ++ publishQueue(global, fs['___graceful-fs_queue']); |
| 81 | + } |
| 82 | + |
| 83 | + module.exports = patch(clone(fs)) |
| 84 | +@@ -370,7 +352,7 @@ function patch (fs) { |
| 85 | + |
| 86 | + function enqueue (elem) { |
| 87 | + debug('ENQUEUE', elem[0].name, elem[1]) |
| 88 | +- fs[gracefulQueue].push(elem) |
| 89 | ++ fs['___graceful-fs_queue'].push(elem) |
| 90 | + retry() |
| 91 | + } |
| 92 | + |
| 93 | +@@ -382,12 +364,12 @@ var retryTimer |
| 94 | + // delay between attempts so that we'll retry these jobs sooner |
| 95 | + function resetQueue () { |
| 96 | + var now = Date.now() |
| 97 | +- for (var i = 0; i < fs[gracefulQueue].length; ++i) { |
| 98 | ++ for (var i = 0; i < fs['___graceful-fs_queue'].length; ++i) { |
| 99 | + // entries that are only a length of 2 are from an older version, don't |
| 100 | + // bother modifying those since they'll be retried anyway. |
| 101 | +- if (fs[gracefulQueue][i].length > 2) { |
| 102 | +- fs[gracefulQueue][i][3] = now // startTime |
| 103 | +- fs[gracefulQueue][i][4] = now // lastTime |
| 104 | ++ if (fs['___graceful-fs_queue'][i].length > 2) { |
| 105 | ++ fs['___graceful-fs_queue'][i][3] = now // startTime |
| 106 | ++ fs['___graceful-fs_queue'][i][4] = now // lastTime |
| 107 | + } |
| 108 | + } |
| 109 | + // call retry to make sure we're actively processing the queue |
| 110 | +@@ -399,10 +381,10 @@ function retry () { |
| 111 | + clearTimeout(retryTimer) |
| 112 | + retryTimer = undefined |
| 113 | + |
| 114 | +- if (fs[gracefulQueue].length === 0) |
| 115 | ++ if (fs['___graceful-fs_queue'].length === 0) |
| 116 | + return |
| 117 | + |
| 118 | +- var elem = fs[gracefulQueue].shift() |
| 119 | ++ var elem = fs['___graceful-fs_queue'].shift() |
| 120 | + var fn = elem[0] |
| 121 | + var args = elem[1] |
| 122 | + // these items may be unset if they were added by an older graceful-fs |
| 123 | +@@ -437,7 +419,7 @@ function retry () { |
| 124 | + } else { |
| 125 | + // if we can't do this job yet, push it to the end of the queue |
| 126 | + // and let the next iteration check again |
| 127 | +- fs[gracefulQueue].push(elem) |
| 128 | ++ fs['___graceful-fs_queue'].push(elem) |
| 129 | + } |
| 130 | + } |
| 131 | + |
0 commit comments