diff --git a/lib/torrent.js b/lib/torrent.js index 3d0ba168..71ee9dcb 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -1154,8 +1154,20 @@ Torrent.prototype._checkDone = function () { debug('file done: ' + file.name) }) - // is the torrent done? - if (self.files.every(function (file) { return file.done })) { + // is the torrent done? (if all current selections are satisfied, or there are + // no selections, then torrent is done) + var done = true + for (var i = 0; i < self._selections.length; i++) { + var selection = self._selections[i] + for (var piece = selection.from; piece <= selection.to; piece++) { + if (!self.bitfield.get(piece)) { + done = false + break + } + } + if (!done) break + } + if (!self.done && done) { self.done = true self.emit('done') debug('torrent done: ' + self.infoHash)