diff --git a/lib/file.js b/lib/file.js index 340ff37f..6881676a 100644 --- a/lib/file.js +++ b/lib/file.js @@ -26,6 +26,7 @@ function File (torrent, file) { this.offset = file.offset this.done = false + this.deselected = false var start = file.offset var end = start + file.length - 1 @@ -45,6 +46,7 @@ function File (torrent, file) { */ File.prototype.select = function () { if (this.length === 0) return + this.deselected = false this._torrent.select(this._startPiece, this._endPiece, false) } @@ -54,6 +56,7 @@ File.prototype.select = function () { */ File.prototype.deselect = function () { if (this.length === 0) return + this.deselected = true this._torrent.deselect(this._startPiece, this._endPiece, false) } diff --git a/lib/torrent.js b/lib/torrent.js index 00415f39..aadec486 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -1153,7 +1153,7 @@ Torrent.prototype._checkDone = function () { }) // is the torrent done? - if (self.files.every(function (file) { return file.done })) { + if (self.files.every(function (file) { return file.done || file.deselected })) { self.done = true self.emit('done') debug('torrent done: ' + self.infoHash)