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>2019-07-09 06:03:30 +0300
committerGitHub <noreply@github.com>2019-07-09 06:03:30 +0300
commitcd965233cc2b8aa89fce971e9bdefd6a6975b66c (patch)
treea6133d9f7b5cd612a80f5e26b39cbb104208f60b /lib
parent3a9f5d6a0bc57b4af3859ff573811849e4756326 (diff)
parentae8988848f4328727b321079922a2a5ed735d6ec (diff)
Merge pull request #1650 from jhiesey/rescan
Add torrent.rescanFiles() to allow manual verify
Diffstat (limited to 'lib')
-rw-r--r--lib/torrent.js33
1 files changed, 25 insertions, 8 deletions
diff --git a/lib/torrent.js b/lib/torrent.js
index c81d33b..7acad70 100644
--- a/lib/torrent.js
+++ b/lib/torrent.js
@@ -505,6 +505,12 @@ class Torrent extends EventEmitter {
this._markAllVerified()
this._onStore()
} else {
+ const onPiecesVerified = (err) => {
+ if (err) return this._destroy(err)
+ this._debug('done verifying')
+ this._onStore()
+ }
+
this._debug('verifying existing torrent data')
if (this._fileModtimes && this._store === FSChunkStore) {
// don't verify if the files haven't been modified since we last checked
@@ -517,11 +523,11 @@ class Torrent extends EventEmitter {
this._markAllVerified()
this._onStore()
} else {
- this._verifyPieces()
+ this._verifyPieces(onPiecesVerified)
}
})
} else {
- this._verifyPieces()
+ this._verifyPieces(onPiecesVerified)
}
}
@@ -547,8 +553,8 @@ class Torrent extends EventEmitter {
})
}
- _verifyPieces () {
- parallelLimit(this.pieces.map((_, index) => cb => {
+ _verifyPieces (cb) {
+ parallelLimit(this.pieces.map((piece, index) => cb => {
if (this.destroyed) return cb(new Error('torrent is destroyed'))
this.store.get(index, (err, buf) => {
@@ -568,10 +574,21 @@ class Torrent extends EventEmitter {
cb(null)
})
})
- }), FILESYSTEM_CONCURRENCY, err => {
- if (err) return this._destroy(err)
- this._debug('done verifying')
- this._onStore()
+ }), FILESYSTEM_CONCURRENCY, cb)
+ }
+
+ rescanFiles (cb) {
+ if (this.destroyed) throw new Error('torrent is destroyed')
+ if (!cb) cb = noop
+
+ this._verifyPieces((err) => {
+ if (err) {
+ this._destroy(err)
+ return cb(err)
+ }
+
+ this._checkDone()
+ cb(null)
})
}