From c715a4a833a499f3aaac5e205560ab6f8e5c07b9 Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Sun, 26 Nov 2023 11:57:50 +0100 Subject: [PATCH] Allow to retain repair status and unselect status --- internal/torrent/manager.go | 5 +---- internal/universal/get.go | 6 +++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/internal/torrent/manager.go b/internal/torrent/manager.go index 8deb86f..95e64de 100644 --- a/internal/torrent/manager.go +++ b/internal/torrent/manager.go @@ -143,7 +143,7 @@ func (t *TorrentManager) mergeToMain(mainTorrent, torrentToMerge *Torrent) *Torr // Merge SelectedFiles - itercb accesses a different copy of the selectedfiles map torrentToMerge.SelectedFiles.IterCb(func(filepath string, fileToMerge *File) { // see if it already exists in the main torrent - if mainFile, ok := mainTorrent.SelectedFiles.Get(filepath); !ok { + if _, ok := mainTorrent.SelectedFiles.Get(filepath); !ok { // if it doesn't exist in the main torrent, add it mainTorrent.SelectedFiles.Set(filepath, fileToMerge) } else { @@ -151,9 +151,6 @@ func (t *TorrentManager) mergeToMain(mainTorrent, torrentToMerge *Torrent) *Torr if mainTorrent.LatestAdded < torrentToMerge.LatestAdded && strings.HasPrefix(fileToMerge.Link, "http") { // if torrentToMerge is more recent and its file has a link, update the main torrent's file mainTorrent.SelectedFiles.Set(filepath, fileToMerge) - } else if !strings.HasPrefix(mainFile.Link, "http") && strings.HasPrefix(fileToMerge.Link, "http") { - // if the main torrent's file link is empty and t2's file has a link, even if it's older, update it - mainTorrent.SelectedFiles.Set(filepath, fileToMerge) } // else do nothing, the main torrent's file is more recent or has a valid link } diff --git a/internal/universal/get.go b/internal/universal/get.go index a1205f4..128a072 100644 --- a/internal/universal/get.go +++ b/internal/universal/get.go @@ -93,7 +93,7 @@ func (gf *GetFile) HandleGetRequest(w http.ResponseWriter, r *http.Request, t *i resp := t.UnrestrictUntilOk(link) if resp == nil { - log.Warnf("File %s is no longer available", filepath.Base(file.Path)) + log.Warnf("File %s is no longer available, file is marked for repair", filepath.Base(file.Path)) file.Link = "repair" t.SetChecksum("") // force a recheck gf.playErrorVideo("https://www.youtube.com/watch?v=gea_FJrtFVA", w, r, t, c, log) @@ -140,7 +140,7 @@ func (gf *GetFile) streamFileToResponse(file *intTor.File, url string, w http.Re resp, err := gf.client.Do(req) if err != nil { if file != nil { - log.Warnf("Cannot download file %s: %v", file.Path, err) + log.Warnf("Cannot download file %s, file is marked for repair: %v", file.Path, err) file.Link = "repair" torMgr.SetChecksum("") // force a recheck } @@ -151,7 +151,7 @@ func (gf *GetFile) streamFileToResponse(file *intTor.File, url string, w http.Re if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusPartialContent { if file != nil { - log.Warnf("Received a %s status code for file %s", resp.Status, file.Path) + log.Warnf("Received a %s status code for file %s, file is marked for repair", resp.Status, file.Path) file.Link = "repair" torMgr.SetChecksum("") // force a recheck }