Prevent duplicates
This commit is contained in:
@@ -371,6 +371,8 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, selection []string)
|
||||
}
|
||||
|
||||
// redownload torrent
|
||||
var newTorrentID string
|
||||
prevState := t.latestState
|
||||
resp, err := t.api.AddMagnetHash(torrent.Hash)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "infringing") {
|
||||
@@ -386,10 +388,20 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, selection []string)
|
||||
} else if strings.Contains(err.Error(), "allowed") {
|
||||
t.markAsUnfixable(torrent, "torrent not allowed")
|
||||
}
|
||||
return nil, fmt.Errorf("cannot add magnet of torrent %s (hash=%s): %v", t.GetKey(torrent), torrent.Hash, err)
|
||||
if strings.Contains(err.Error(), "timeout") {
|
||||
newState := t.getCurrentState()
|
||||
if prevState.Eq(newState) {
|
||||
return t.redownloadTorrent(torrent, selection)
|
||||
}
|
||||
newTorrentID = t.latestState.FirstTorrentId
|
||||
} else {
|
||||
return nil, fmt.Errorf("cannot add magnet of torrent %s (hash=%s): %v", t.GetKey(torrent), torrent.Hash, err)
|
||||
}
|
||||
}
|
||||
|
||||
newTorrentID := resp.ID
|
||||
if resp != nil {
|
||||
newTorrentID = resp.ID
|
||||
}
|
||||
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user