From 50493203791857060aea4935470074397a677744 Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Tue, 16 Jan 2024 21:40:07 +0100 Subject: [PATCH] Fix repairs --- internal/torrent/manager.go | 5 +++-- internal/torrent/refresh.go | 4 ++-- internal/torrent/repair.go | 22 ++++------------------ 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/internal/torrent/manager.go b/internal/torrent/manager.go index 26bda3e..9899864 100644 --- a/internal/torrent/manager.go +++ b/internal/torrent/manager.go @@ -29,7 +29,7 @@ type TorrentManager struct { DownloadMap cmap.ConcurrentMap[string, *realdebrid.Download] Repairs cmap.ConcurrentMap[string, bool] allAccessKeys mapset.Set[string] - forRepairs mapset.Set[string] + onlyForRepair mapset.Set[string] latestState *LibraryState requiredVersion string workerPool *ants.Pool @@ -44,7 +44,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p Config: cfg, Api: api, allAccessKeys: mapset.NewSet[string](), - forRepairs: mapset.NewSet[string](), + onlyForRepair: mapset.NewSet[string](), latestState: &LibraryState{}, requiredVersion: "11.01.2024", workerPool: p, @@ -63,6 +63,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p // Fetch downloads t.DownloadCache = cmap.New[*realdebrid.Download]() t.DownloadMap = cmap.New[*realdebrid.Download]() + t.Repairs = cmap.New[bool]() if t.Config.EnableDownloadCache() { _ = t.workerPool.Submit(func() { page := 1 diff --git a/internal/torrent/refresh.go b/internal/torrent/refresh.go index 2bd8406..9dc7e2d 100644 --- a/internal/torrent/refresh.go +++ b/internal/torrent/refresh.go @@ -45,13 +45,13 @@ func (t *TorrentManager) RefreshTorrents() []string { continue } torrentIDs := info.DownloadedIDs.ToSlice() - if !info.AnyInProgress() && len(torrentIDs) > 0 && t.forRepairs.Contains(info.DownloadedIDs.ToSlice()[0]) { + if !info.AnyInProgress() && len(torrentIDs) > 0 && t.onlyForRepair.Contains(info.DownloadedIDs.ToSlice()[0]) { torrentID := info.DownloadedIDs.ToSlice()[0] // if it's 100% and it's a temp repair, remove it t.Api.DeleteTorrent(torrentID) toReinsert.Add(t.GetKey(info)) infoChan <- nil - t.forRepairs.Remove(torrentID) + t.onlyForRepair.Remove(torrentID) continue } if !info.AnyInProgress() { diff --git a/internal/torrent/repair.go b/internal/torrent/repair.go index 3ba5a09..e481568 100644 --- a/internal/torrent/repair.go +++ b/internal/torrent/repair.go @@ -212,20 +212,6 @@ func (t *TorrentManager) repair(torrent *Torrent) { }) t.log.Debugf("During repair, zurg found %d broken files for torrent %s", len(brokenFiles), t.GetKey(torrent)) - if len(brokenFiles) == 1 && torrent.SelectedFiles.Count() > 2 { - // if we download a single file, it will be named differently - // so we need to download 1 extra file to preserve the name - // this is only relevant if we enable retain_rd_torrent_name - // add the first file link encountered with a prefix of http - t.log.Debugf("Torrent %s has only 1 broken file, adding 1 extra file to preserve the name", t.GetKey(torrent)) - for _, file := range torrent.SelectedFiles.Items() { - if strings.HasPrefix(file.Link, "http") { - brokenFiles = append(brokenFiles, *file) - break - } - } - } - if len(brokenFiles) > 0 { t.log.Infof("Redownloading %dof%d files for torrent %s", len(brokenFiles), torrent.SelectedFiles.Count(), t.GetKey(torrent)) brokenFileIDs := strings.Join(getFileIDs(brokenFiles), ",") @@ -305,13 +291,13 @@ func (t *TorrentManager) reinsertTorrent(torrent *Torrent, brokenFiles string) b if info.Progress != 100 { t.log.Infof("Torrent id=%s is not cached anymore so we have to wait until completion (this should fix the issue already)", info.ID) - t.forRepairs.Add(newTorrentID) + t.onlyForRepair.Add(newTorrentID) if len(oldTorrentIDs) > 0 { for _, id := range oldTorrentIDs { t.Api.DeleteTorrent(id) } } else { - t.forRepairs.Add(newTorrentID) + t.onlyForRepair.Add(newTorrentID) } return true } @@ -324,13 +310,13 @@ func (t *TorrentManager) reinsertTorrent(torrent *Torrent, brokenFiles string) b } t.log.Infof("Repair successful id=%s", newTorrentID) - t.forRepairs.Add(newTorrentID) + t.onlyForRepair.Add(newTorrentID) if len(oldTorrentIDs) > 0 { for _, id := range oldTorrentIDs { t.Api.DeleteTorrent(id) } } else { - t.forRepairs.Add(newTorrentID) + t.onlyForRepair.Add(newTorrentID) } return true }