diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2015-12-28 18:50:02 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2015-12-28 18:50:02 +0300 |
commit | 0ea039fafcd0966fc8d14eaed84439d3d0791711 (patch) | |
tree | 9c7321ae9a14556171b309c6017089fbb1a2ab5a /lib | |
parent | 9339f058a0e66a8f9347ba11410ba3e7eb3d1008 (diff) |
Fix torrent.done state when there are deselected files (fix #316)
Supersedes PR https://github.com/feross/webtorrent/pull/533
Diffstat (limited to 'lib')
-rw-r--r-- | lib/torrent.js | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index 3d0ba16..71ee9dc 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) |