Remove components, do downloaded ids ; support dumps

This commit is contained in:
Ben Sarmiento
2024-05-24 02:24:26 +02:00
parent beba993364
commit 9ecbb5d892
8 changed files with 188 additions and 107 deletions

View File

@@ -156,7 +156,7 @@ func (t *TorrentManager) Repair(torrent *Torrent, wg *sync.WaitGroup) {
}
func (t *TorrentManager) repair(torrent *Torrent) {
torrentIDs := torrent.Components.Keys()
torrentIDs := torrent.DownloadedIDs.ToSlice()
t.log.Infof("Started repair process for torrent %s (ids=%v)", t.GetKey(torrent), torrentIDs)
// handle torrents with incomplete links for selected files
@@ -180,10 +180,11 @@ func (t *TorrentManager) repair(torrent *Torrent) {
return
}
// delete old torrents
torrent.Components.IterCb(func(id string, _ *realdebrid.TorrentInfo) {
if id != info.ID {
t.api.DeleteTorrent(id)
torrent.DownloadedIDs.Each(func(torrentID string) bool {
if torrentID != info.ID {
t.setToBinOnceDone(torrentID)
}
return false
})
t.log.Infof("Successfully repaired torrent %s by redownloading all files", t.GetKey(torrent))
return
@@ -212,7 +213,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
return
}
t.log.Infof("Torrent %s will be repaired by downloading %d batches of the %d broken files", int(math.Ceil(float64(len(brokenFiles))/100)), len(brokenFiles), t.GetKey(torrent))
t.log.Infof("Torrent %s will be repaired by downloading %d batches of the %d broken files", t.GetKey(torrent), int(math.Ceil(float64(len(brokenFiles))/100)), len(brokenFiles))
newlyDownloadedIds := make([]string, 0)
batchNum := 1
@@ -227,7 +228,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
if err != nil {
t.log.Warnf("Cannot repair torrent %s by downloading broken files (error=%s) giving up", t.GetKey(torrent), err.Error())
for _, newId := range newlyDownloadedIds {
t.trash(newId)
t.setToBinImmediately(newId)
}
return
}
@@ -243,7 +244,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
if err != nil {
t.log.Warnf("Cannot repair torrent %s by downloading broken files (error=%s) giving up", t.GetKey(torrent), err.Error())
for _, newId := range newlyDownloadedIds {
t.trash(newId)
t.setToBinImmediately(newId)
}
return
}
@@ -251,7 +252,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
}
for _, newId := range newlyDownloadedIds {
t.trashOnceCompleted(newId)
t.setToBinOnceDone(newId)
}
}
@@ -398,7 +399,7 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, selection []string)
// select files
err = t.api.SelectTorrentFiles(newTorrentID, finalSelection)
if err != nil {
t.trash(newTorrentID)
t.setToBinImmediately(newTorrentID)
return nil, fmt.Errorf("cannot start redownloading torrent %s (id=%s): %v", t.GetKey(torrent), newTorrentID, err)
}
// sleep for 2 second to let RD process the magnet
@@ -407,7 +408,7 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, selection []string)
// see if the torrent is ready
info, err = t.api.GetTorrentInfo(newTorrentID)
if err != nil {
t.trash(newTorrentID)
t.setToBinImmediately(newTorrentID)
return nil, fmt.Errorf("cannot get info on redownloaded torrent %s (id=%s) : %v", t.GetKey(torrent), newTorrentID, err)
}
@@ -433,13 +434,13 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, selection []string)
}
if !isOkStatus {
t.trash(info.ID)
t.setToBinImmediately(info.ID)
return nil, fmt.Errorf("the redownloaded torrent %s is in a non-OK state: %s", t.GetKey(torrent), info.Status)
}
// check if incorrect number of links
if info.Progress == 100 && len(info.Links) != len(selection) {
t.trash(newTorrentID)
t.setToBinImmediately(newTorrentID)
return nil, fmt.Errorf("torrent %s only got %d links but we need %d", t.GetKey(torrent), len(info.Links), len(selection))
}