Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix torrent.done state when there are deselected files (fix #316) #544

Merged
merged 1 commit into from Dec 28, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -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

This comment has been minimized.

Copy link
@feross

feross Dec 28, 2015

Author Member

This isn't strictly necessary – just an optimization

}
}
if (!done) break

This comment has been minimized.

Copy link
@feross

feross Dec 28, 2015

Author Member

Same here – this is just an optimization

}
if (!self.done && done) {

This comment has been minimized.

Copy link
@feross

feross Dec 28, 2015

Author Member

This is an extra safety-net to ensure we don't emit 'done' twice.

self.done = true
self.emit('done')
debug('torrent done: ' + self.infoHash)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.