From 24c2ad5a46c15e624ab282b03a509de0353870bf Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Fri, 17 Jun 2016 21:49:09 +1000 Subject: [PATCH] collect: respect stream pause / resume state Without watching if a stream is already paused before calling pause(), collect() can conflict with other users of the stream who may be managing state, resulting in a premature collect(). This manifests in the fstream-npm and node-tar combination where fstream-npm manages state in readBundledLinks() at the same time collect() is processing the stream. collect() ends up running before fstream-npm has properly set up the _correct_ list of entries according to the ignore rules. When collect() gets to run before this is complete, fstream starts performing _read() operations on a non-filtered list, keeping track of entry index, then after it starts, fstream-npm inserts a new list of entries and the entry index is incorrect and can skip files. Fixes: npm/npm#5082 Credit: @rvagg Reviewed-By: @othiym23 PR-URL: https://github.com/npm/fstream/pull/53 --- lib/collect.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/collect.js b/lib/collect.js index 6245e6c..e5d4f35 100644 --- a/lib/collect.js +++ b/lib/collect.js @@ -3,6 +3,8 @@ module.exports = collect function collect (stream) { if (stream._collected) return + if (stream._paused) return stream.on('resume', collect.bind(null, stream)) + stream._collected = true stream.pause()