Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2015-12-28 18:50:02 +0300
committerFeross Aboukhadijeh <feross@feross.org>2015-12-28 18:50:02 +0300
commit0ea039fafcd0966fc8d14eaed84439d3d0791711 (patch)
tree9c7321ae9a14556171b309c6017089fbb1a2ab5a /lib
parent9339f058a0e66a8f9347ba11410ba3e7eb3d1008 (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.js16
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)