This repository has been archived by the owner on Aug 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
read: account for entries changed after _read
If this.entries is changed after _read() has been called, we will be out of sync and try to access an invalid index of this.entries. When the entry cannot be found, we emit end and close, which can drop files from reading. (At least partially) fixes npm/npm#5082. Credit: @evanlucas Reviewed-By: @othiym23 PR-URL: #50
- Loading branch information
Showing
1 changed file
with
9 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ function DirReader (props) { | |
} | ||
|
||
self.entries = null | ||
self._entries = [] | ||
self._index = -1 | ||
self._paused = false | ||
self._length = -1 | ||
|
@@ -47,6 +48,7 @@ DirReader.prototype._getEntries = function () { | |
if (er) return self.error(er) | ||
|
||
self.entries = entries | ||
self._entries = entries.slice() | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
othiym23
Contributor
|
||
self.emit('entries', entries) | ||
if (self._paused) self.once('resume', processEntries) | ||
|
@@ -74,7 +76,7 @@ DirReader.prototype._read = function () { | |
} | ||
|
||
self._index++ | ||
if (self._index >= self.entries.length) { | ||
if (self._index >= self._entries.length) { | ||
if (!self._ended) { | ||
self._ended = true | ||
self.emit('end') | ||
|
@@ -83,12 +85,14 @@ DirReader.prototype._read = function () { | |
return | ||
} | ||
|
||
// ok, handle this one, then. | ||
|
||
// save creating a proxy, by stat'ing the thing now. | ||
var p = path.resolve(self._path, self.entries[self._index]) | ||
var nextEntry = self._entries[self._index] | ||
if (!nextEntry) return this._read() | ||
|
||
// ok, handle this one, then. | ||
var p = path.resolve(self._path, nextEntry) | ||
assert(p !== self._path) | ||
assert(self.entries[self._index]) | ||
assert(nextEntry) | ||
|
||
// set this to prevent trying to _read() again in the stat time. | ||
self._currentEntry = p | ||
|
What's the distinction between
_entries
andentries
? (I mean beyond than the shallow clone)