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

Add opts.skipVerify to skip verifying existing data #1434

Merged
merged 1 commit into from Jul 18, 2018
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

Add opts.skipVerify to skip verifying existing data

  • Loading branch information
jhiesey committed Jul 17, 2018
commit 7d242dc034564776b3607ad06d2749bb71a15775
@@ -74,6 +74,7 @@ function Torrent (torrentId, client, opts) {
this.urlList = opts.urlList

this.path = opts.path
this.skipVerify = !!opts.skipVerify
this._store = opts.store || FSChunkStore
this._getAnnounceOpts = opts.getAnnounceOpts

@@ -542,29 +543,33 @@ Torrent.prototype._onMetadata = function (metadata) {
self._onWireWithMetadata(wire)
})

self._debug('verifying existing torrent data')
if (self._fileModtimes && self._store === FSChunkStore) {
// don't verify if the files haven't been modified since we last checked
self.getFileModtimes(function (err, fileModtimes) {
if (err) return self._destroy(err)

var unchanged = self.files.map(function (_, index) {
return fileModtimes[index] === self._fileModtimes[index]
}).every(function (x) {
return x
})
if (self.skipVerify) {
// Skip verifying exisitng data and just assume it's correct
self._markAllVerified()
self._onStore()
} else {
self._debug('verifying existing torrent data')
if (self._fileModtimes && self._store === FSChunkStore) {
// don't verify if the files haven't been modified since we last checked
self.getFileModtimes(function (err, fileModtimes) {
if (err) return self._destroy(err)

var unchanged = self.files.map(function (_, index) {
return fileModtimes[index] === self._fileModtimes[index]
}).every(function (x) {
return x
})

if (unchanged) {
for (var index = 0; index < self.pieces.length; index++) {
self._markVerified(index)
if (unchanged) {
self._markAllVerified()
self._onStore()
} else {
self._verifyPieces()
}
self._onStore()
} else {
self._verifyPieces()
}
})
} else {
self._verifyPieces()
})
} else {
self._verifyPieces()
}
}

self.emit('metadata')
@@ -623,6 +628,12 @@ Torrent.prototype._verifyPieces = function () {
})
}

Torrent.prototype._markAllVerified = function () {
for (var index = 0; index < this.pieces.length; index++) {
this._markVerified(index)
}
}

Torrent.prototype._markVerified = function (index) {
this.pieces[index] = null
this._reservations[index] = null
@@ -1625,11 +1636,7 @@ Torrent.prototype.load = function (streams, cb) {

pump(readable, writable, function (err) {
if (err) return cb(err)
self.pieces.forEach(function (piece, index) {
self.pieces[index] = null
self._reservations[index] = null
self.bitfield.set(index, true)
})
self._markAllVerified()
self._checkDone()
cb(null)
})
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.