Ignore errors when marking torrent as repaired (also mute warnings when under repair)

This commit is contained in:
Ben Sarmiento
2024-05-24 18:00:46 +02:00
parent 6d07645361
commit 7695412b22
4 changed files with 9 additions and 18 deletions

View File

@@ -262,9 +262,7 @@ func (t *TorrentManager) convertToTorrent(info *realdebrid.TorrentInfo) *Torrent
} }
} }
torrent.UnassignedLinks = mapset.NewSet[string]() torrent.UnassignedLinks = mapset.NewSet[string]()
if err := torrent.State.Event(context.Background(), "mark_as_repaired"); err != nil { torrent.State.Event(context.Background(), "mark_as_repaired")
t.log.Errorf("Cannot repair torrent %s: %v", torrent.Hash, err)
}
} else { } else {
torrent.UnassignedLinks = mapset.NewSet[string]() torrent.UnassignedLinks = mapset.NewSet[string]()
for _, link := range info.Links { for _, link := range info.Links {
@@ -361,9 +359,7 @@ func (t *TorrentManager) mergeTorrents(existing, toMerge *Torrent) *Torrent {
}) })
if brokenCount == 0 && okCount > 0 { if brokenCount == 0 && okCount > 0 {
if err := mergedTorrent.State.Event(context.Background(), "mark_as_repaired"); err != nil { mergedTorrent.State.Event(context.Background(), "mark_as_repaired")
t.log.Errorf("Cannot repair torrent %s: %v", t, t.GetKey(mergedTorrent), err)
}
} }
return mergedTorrent return mergedTorrent

View File

@@ -182,10 +182,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
info, err := t.redownloadTorrent(torrent, []string{}) // reinsert the whole torrent, passing empty selection info, err := t.redownloadTorrent(torrent, []string{}) // reinsert the whole torrent, passing empty selection
if info != nil && info.Progress == 100 && !t.isStillBroken(info, brokenFiles) { if info != nil && info.Progress == 100 && !t.isStillBroken(info, brokenFiles) {
// successful repair // successful repair
if err := torrent.State.Event(context.Background(), "mark_as_repaired"); err != nil { torrent.State.Event(context.Background(), "mark_as_repaired")
t.log.Errorf("Cannot repair torrent %s: %v", torrent.Hash, err)
return
}
// delete old torrents // delete old torrents
torrent.DownloadedIDs.Each(func(torrentID string) bool { torrent.DownloadedIDs.Each(func(torrentID string) bool {
if torrentID != info.ID { if torrentID != info.ID {
@@ -202,7 +199,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
} }
if err != nil { if err != nil {
t.log.Warnf("Cannot repair torrent %s by redownloading all files (error=%s)", t.GetKey(torrent), err.Error()) t.log.Warnf("Cannot repair torrent %s by redownloading all files (error=%v)", t.GetKey(torrent), err)
} else { } else {
t.log.Warnf("Cannot repair torrent %s by redownloading all files", t.GetKey(torrent)) t.log.Warnf("Cannot repair torrent %s by redownloading all files", t.GetKey(torrent))
} }
@@ -234,7 +231,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
batchNum++ batchNum++
redownloadedInfo, err := t.redownloadTorrent(torrent, group) redownloadedInfo, err := t.redownloadTorrent(torrent, group)
if err != nil { if err != nil {
t.log.Warnf("Cannot repair torrent %s by downloading broken files (error=%s) giving up", t.GetKey(torrent), err.Error()) t.log.Warnf("Cannot repair torrent %s by downloading broken files (error=%v) giving up", t.GetKey(torrent), err)
for _, newId := range newlyDownloadedIds { for _, newId := range newlyDownloadedIds {
t.setToBinImmediately(newId) t.setToBinImmediately(newId)
} }
@@ -250,7 +247,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
if len(group) > 0 { if len(group) > 0 {
redownloadedInfo, err := t.redownloadTorrent(torrent, group) redownloadedInfo, err := t.redownloadTorrent(torrent, group)
if err != nil { if err != nil {
t.log.Warnf("Cannot repair torrent %s by downloading broken files (error=%s) giving up", t.GetKey(torrent), err.Error()) t.log.Warnf("Cannot repair torrent %s by downloading broken files (error=%v) giving up", t.GetKey(torrent), err)
for _, newId := range newlyDownloadedIds { for _, newId := range newlyDownloadedIds {
t.setToBinImmediately(newId) t.setToBinImmediately(newId)
} }
@@ -353,9 +350,7 @@ func (t *TorrentManager) assignLinks(torrent *Torrent) bool {
torrent.UnassignedLinks = mapset.NewSet[string]() torrent.UnassignedLinks = mapset.NewSet[string]()
t.markAsUnfixable(torrent, "rar'ed by RD") t.markAsUnfixable(torrent, "rar'ed by RD")
t.markAsUnplayable(torrent, "rar'ed by RD") t.markAsUnplayable(torrent, "rar'ed by RD")
if err := torrent.State.Event(context.Background(), "mark_as_repaired"); err != nil { torrent.State.Event(context.Background(), "mark_as_repaired")
t.log.Errorf("Cannot repair torrent %s: %v", torrent.Hash, err)
}
} }
return false // end repair return false // end repair
} }

View File

@@ -28,7 +28,7 @@ func CheckFile(directory, torrentName, fileName string, w http.ResponseWriter, r
file, ok := torrent.SelectedFiles.Get(fileName) file, ok := torrent.SelectedFiles.Get(fileName)
if !ok || !file.State.Is("ok_file") { if !ok || !file.State.Is("ok_file") {
log.Warnf("Cannot find file %s from path %s", fileName, req.URL.Path) // log.Warnf("Cannot find file %s from path %s", fileName, req.URL.Path)
http.Error(w, "File not found", http.StatusNotFound) http.Error(w, "File not found", http.StatusNotFound)
return return
} }

View File

@@ -51,7 +51,7 @@ func (dl *Downloader) DownloadFile(
file, ok := torrent.SelectedFiles.Get(fileName) file, ok := torrent.SelectedFiles.Get(fileName)
if !ok || !file.State.Is("ok_file") { if !ok || !file.State.Is("ok_file") {
log.Warnf("Cannot find file %s from path %s", fileName, req.URL.Path) // log.Warnf("Cannot find file %s from path %s", fileName, req.URL.Path)
http.Error(resp, "File not found", http.StatusNotFound) http.Error(resp, "File not found", http.StatusNotFound)
return return
} }