Merge pull request #489 from feross/fix-add-duplicate
Fix duplicate torrent handling
This commit is contained in:
@@ -11,5 +11,4 @@ function init () {
|
|||||||
productName: config.APP_NAME,
|
productName: config.APP_NAME,
|
||||||
submitURL: config.CRASH_REPORT_URL
|
submitURL: config.CRASH_REPORT_URL
|
||||||
})
|
})
|
||||||
console.log('crash reporter started')
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
console.time('init')
|
||||||
|
|
||||||
var electron = require('electron')
|
var electron = require('electron')
|
||||||
|
|
||||||
var app = electron.app
|
var app = electron.app
|
||||||
@@ -67,6 +69,7 @@ function init () {
|
|||||||
app.on('ipcReady', function () {
|
app.on('ipcReady', function () {
|
||||||
log('Command line args:', argv)
|
log('Command line args:', argv)
|
||||||
processArgv(argv)
|
processArgv(argv)
|
||||||
|
console.timeEnd('init')
|
||||||
})
|
})
|
||||||
|
|
||||||
app.on('before-quit', function (e) {
|
app.on('before-quit', function (e) {
|
||||||
|
|||||||
@@ -25,10 +25,9 @@ var vlcProcess
|
|||||||
|
|
||||||
function init () {
|
function init () {
|
||||||
ipcMain.on('ipcReady', function (e) {
|
ipcMain.on('ipcReady', function (e) {
|
||||||
|
windows.main.show()
|
||||||
app.ipcReady = true
|
app.ipcReady = true
|
||||||
app.emit('ipcReady')
|
app.emit('ipcReady')
|
||||||
windows.main.show()
|
|
||||||
console.timeEnd('init')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('ipcReadyWebTorrent', function (e) {
|
ipcMain.on('ipcReadyWebTorrent', function (e) {
|
||||||
|
|||||||
@@ -724,16 +724,16 @@ function torrentWarning (torrentKey, message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function torrentError (torrentKey, message) {
|
function torrentError (torrentKey, message) {
|
||||||
var torrentSummary = getTorrentSummary(torrentKey)
|
// TODO: WebTorrent needs semantic errors
|
||||||
|
if (message.startsWith('Cannot add duplicate torrent')) {
|
||||||
// TODO: WebTorrent should have semantic errors
|
// Remove infohash from the message
|
||||||
if (message.startsWith('There is already a swarm')) {
|
message = 'Cannot add duplicate torrent'
|
||||||
onError(new Error('Can\'t add duplicate torrent'))
|
}
|
||||||
} else if (!torrentSummary) {
|
|
||||||
onError(message)
|
onError(message)
|
||||||
} else {
|
|
||||||
console.log('error, stopping torrent %s (%s):\n\t%o',
|
var torrentSummary = getTorrentSummary(torrentKey)
|
||||||
torrentSummary.name, torrentSummary.infoHash, message)
|
if (torrentSummary) {
|
||||||
|
console.log('Pausing torrent %s due to error: %s', torrentSummary.infoHash, message)
|
||||||
torrentSummary.status = 'paused'
|
torrentSummary.status = 'paused'
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,23 +68,14 @@ function init () {
|
|||||||
// See https://github.com/feross/webtorrent/blob/master/docs/api.md#clientaddtorrentid-opts-function-ontorrent-torrent-
|
// See https://github.com/feross/webtorrent/blob/master/docs/api.md#clientaddtorrentid-opts-function-ontorrent-torrent-
|
||||||
function startTorrenting (torrentKey, torrentID, path, fileModtimes) {
|
function startTorrenting (torrentKey, torrentID, path, fileModtimes) {
|
||||||
console.log('starting torrent %s: %s', torrentKey, torrentID)
|
console.log('starting torrent %s: %s', torrentKey, torrentID)
|
||||||
var torrent
|
|
||||||
try {
|
var torrent = client.add(torrentID, {
|
||||||
torrent = client.add(torrentID, {
|
|
||||||
path: path,
|
path: path,
|
||||||
fileModtimes: fileModtimes
|
fileModtimes: fileModtimes
|
||||||
})
|
})
|
||||||
} catch (err) {
|
|
||||||
return ipc.send('wt-error', torrentKey, err.message)
|
|
||||||
}
|
|
||||||
// If we add a duplicate magnet URI or infohash, WebTorrent returns the
|
|
||||||
// existing torrent object! (If we add a duplicate torrent file, it creates a
|
|
||||||
// new torrent object and raises an error later.) Workaround:
|
|
||||||
if (torrent.key) {
|
|
||||||
return ipc.send('wt-error', torrentKey, 'Can\'t add duplicate torrent')
|
|
||||||
}
|
|
||||||
torrent.key = torrentKey
|
torrent.key = torrentKey
|
||||||
addTorrentEvents(torrent)
|
addTorrentEvents(torrent)
|
||||||
|
|
||||||
return torrent
|
return torrent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user