Delete if links are still broken or no longer cached

This commit is contained in:
Ben Sarmiento
2024-05-28 02:37:28 +02:00
parent 16e51d50b0
commit 2504b31d4c

View File

@@ -184,7 +184,8 @@ func (t *TorrentManager) repair(torrent *Torrent) {
t.repairLog.Debugf("Torrent %s has %d broken files (out of %d), repairing by redownloading whole torrent", t.GetKey(torrent), len(brokenFiles), torrent.SelectedFiles.Count())
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 {
if !t.isStillBroken(info, brokenFiles) {
// successful repair
torrent.State.Event(context.Background(), "mark_as_repaired")
t.repairLog.Infof("Successfully repaired torrent %s by redownloading whole torrent", t.GetKey(torrent))
@@ -196,22 +197,20 @@ func (t *TorrentManager) repair(torrent *Torrent) {
return false
})
return
} else if info != nil && info.Progress != 100 {
t.repairLog.Infof("Torrent %s is still in progress after redownloading whole torrent but it should be repaired once done", t.GetKey(torrent))
// once info.ID is done, we can delete the old torrent
torrent.DownloadedIDs.Clone().Each(func(torrentID string) bool {
if torrentID != info.ID {
t.setXToBinOnceYDone(torrentID, info.ID)
}
return false
})
return
// if it's still broken, let's delete the newly downloaded torrent
t.setToBinImmediately(info.ID)
err = fmt.Errorf("links are still broken")
} else if info != nil && info.Progress != 100 {
// it's faster to download just the broken files, so let's delete the newly downloaded torrent
t.setToBinImmediately(info.ID)
err = fmt.Errorf("no longer cached")
}
if err != nil {
t.repairLog.Warnf("Cannot repair torrent %s by redownloading whole torrent (error=%v)", t.GetKey(torrent), err)
} else {
t.repairLog.Warnf("Cannot repair torrent %s by redownloading whole torrent (links are still broken)", t.GetKey(torrent))
}
if torrent.UnrepairableReason != "" {