From 9a7d96b21f14f22a3e7ce5ba2dade5070413ffe4 Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Sat, 20 Jan 2024 16:38:09 +0100 Subject: [PATCH] Fix repair done check --- internal/torrent/repair.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/internal/torrent/repair.go b/internal/torrent/repair.go index c2bf97b..9f593b6 100644 --- a/internal/torrent/repair.go +++ b/internal/torrent/repair.go @@ -426,10 +426,30 @@ func getBrokenFiles(torrent *Torrent) []*File { } func (t *TorrentManager) isStillBroken(info *realdebrid.TorrentInfo, brokenFiles []*File) bool { + var selectedFiles []*File + // if some Links are empty, we need to repair it + for _, file := range info.Files { + if file.Selected == 0 { + continue + } + selectedFiles = append(selectedFiles, &File{ + File: file, + Ended: info.Ended, + Link: "", // no link yet + }) + } + if len(selectedFiles) == len(info.Links) { + // all links are still intact! good! + for i, file := range selectedFiles { + file.Link = info.Links[i] + } + } else { + return true + } for _, oldFile := range brokenFiles { - for idx, newFile := range info.Files { + for idx, newFile := range selectedFiles { if oldFile.Path == newFile.Path || oldFile.Bytes == newFile.Bytes { - unrestrict := t.UnrestrictUntilOk(info.Links[idx]) + unrestrict := t.UnrestrictUntilOk(selectedFiles[idx].Link) if unrestrict == nil || oldFile.Bytes != unrestrict.Filesize { return true }