From 52fb378fd5f4b3dc958b7cb2be94c17c823bf8c2 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Tue, 31 May 2016 23:00:02 -0700 Subject: [PATCH] Error on duplicate add --- renderer/main.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/renderer/main.js b/renderer/main.js index d0cc1987..4c6cc0ba 100644 --- a/renderer/main.js +++ b/renderer/main.js @@ -828,21 +828,18 @@ function torrentInfoHash (torrentKey, infoHash) { torrentSummary ? 'existing' : 'new', torrentKey) if (!torrentSummary) { - // Check if another torrent has the same infoHash - var duplicate = state.saved.torrents.find((x) => x.infoHash === infoHash) - - if (duplicate) { - duplicate.torrentKey = torrentKey - duplicate.status = 'new' - sound.play('ENABLE') - } else { - torrentSummary = { - torrentKey: torrentKey, - status: 'new' - } - state.saved.torrents.unshift(torrentSummary) - sound.play('ADD') + // Check if an existing (non-active) torrent has the same info hash + if (state.saved.torrents.find((t) => t.infoHash === infoHash)) { + ipcRenderer.send('wt-stop-torrenting', infoHash) + return onError(new Error('Cannot add duplicate torrent')) } + + torrentSummary = { + torrentKey: torrentKey, + status: 'new' + } + state.saved.torrents.unshift(torrentSummary) + sound.play('ADD') } torrentSummary.infoHash = infoHash