Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

dir-reader: account for entries being changed after _read #50

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/dir-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function DirReader (props) {
}

self.entries = null
self._entries = []
self._index = -1
self._paused = false
self._length = -1
Expand All @@ -47,6 +48,7 @@ DirReader.prototype._getEntries = function () {
if (er) return self.error(er)

self.entries = entries
self._entries = entries.slice()

self.emit('entries', entries)
if (self._paused) self.once('resume', processEntries)
Expand Down Expand Up @@ -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')
Expand All @@ -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
Expand Down