From 29a11ec286520c61fb6015d11fc2370233938085 Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Fri, 26 Jan 2024 16:47:54 +0100 Subject: [PATCH] Infinite repair fix --- internal/torrent/repair.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/internal/torrent/repair.go b/internal/torrent/repair.go index c1b5ab7..0e142cc 100644 --- a/internal/torrent/repair.go +++ b/internal/torrent/repair.go @@ -146,6 +146,11 @@ func (t *TorrentManager) repair(torrent *Torrent) { t.log.Infof("repair_method#1: Torrent %s is still in progress but it should work once done (torrent is temporarily hidden until download has completed)", t.GetKey(torrent)) return } else if info != nil && info.IsDone() && !t.isStillBroken(info, brokenFiles) { + ix := 0 + torrent.SelectedFiles.IterCb(func(_ string, file *File) { + file.Link = info.Links[ix] + ix++ + }) t.log.Infof("Successfully repaired torrent %s using repair_method#1", t.GetKey(torrent)) return } @@ -487,13 +492,23 @@ func (t *TorrentManager) handleFixers(fixer realdebrid.Torrent) *Torrent { } if info.IsDone() { - if t.isStillBroken(info, brokenFiles) { + if !t.isStillBroken(info, brokenFiles) { + ix := 0 + torrent.SelectedFiles.IterCb(func(_ string, file *File) { + for _, brokenFile := range brokenFiles { + if file.ID == brokenFile.ID { + file.Link = info.Links[ix] + ix++ + break + } + } + }) + t.log.Infof("Successfully repaired torrent %s using repair_method#2", t.GetKey(torrent)) + } else { t.log.Warnf("repair_method#2: Fixer is done but torrent %s is still broken; let's keep the fixer", t.GetKey(torrent)) t.Api.DeleteTorrent(info.ID) t.deleteOnceDone.Add(fixer.ID) return t.getMoreInfo(fixer) - } else { - t.log.Infof("Successfully repaired torrent %s using repair_method#2", t.GetKey(torrent)) } } else { t.log.Infof("repair_method#2: Torrent %s is still in progress but it should work once done (torrent is temporarily hidden until download has completed)", t.GetKey(torrent))