100 broken files at a time

This commit is contained in:
Ben Sarmiento
2024-04-30 06:13:21 +02:00
parent 60c0a90899
commit 130cc0d7b3

View File

@@ -210,36 +210,33 @@ func (t *TorrentManager) repair(torrent *Torrent) {
t.log.Infof("Repairing by downloading 2 batches of the %d broken files of torrent %s", len(brokenFiles), t.GetKey(torrent)) t.log.Infof("Repairing by downloading 2 batches of the %d broken files of torrent %s", len(brokenFiles), t.GetKey(torrent))
oldTorrentIDs := torrent.DownloadedIDs.Union(torrent.InProgressIDs).ToSlice() oldTorrentIDs := torrent.DownloadedIDs.Union(torrent.InProgressIDs).ToSlice()
// divide the broken files into 2 groups
group1 := make([]*File, 0) group := make([]*File, 0)
group2 := make([]*File, 0) for _, file := range brokenFiles {
for idx, file := range brokenFiles { group = append(group, file)
if idx%2 == 0 { if len(group) == 100 {
group1 = append(group1, file) brokenFileIDs := getFileIDs(group)
} else { _, err := t.redownloadTorrent(torrent, brokenFileIDs)
group2 = append(group2, file) if err != nil {
} t.log.Warnf("Cannot repair torrent %s by downloading broken files (error=%s) giving up", t.GetKey(torrent), err.Error())
}
brokenFileIDs1 := getFileIDs(group1)
redownloadedInfo1, err1 := t.redownloadTorrent(torrent, brokenFileIDs1)
if err1 != nil {
t.log.Warnf("Cannot repair torrent %s by downloading broken files (error=%s) giving up", t.GetKey(torrent), err1.Error())
return return
} }
if redownloadedInfo1 != nil { group = make([]*File, 0)
brokenFileIDs2 := getFileIDs(group2) }
redownloadedInfo2, err2 := t.redownloadTorrent(torrent, brokenFileIDs2) }
if err2 != nil {
t.log.Warnf("Cannot repair torrent %s by downloading broken files (error=%s) giving up", t.GetKey(torrent), err2.Error()) if len(group) > 0 {
brokenFileIDs := getFileIDs(group)
_, err := t.redownloadTorrent(torrent, brokenFileIDs)
if err != nil {
t.log.Warnf("Cannot repair torrent %s by downloading broken files (error=%s) giving up", t.GetKey(torrent), err.Error())
return return
} }
if redownloadedInfo2 != nil { }
for _, oldId := range oldTorrentIDs { for _, oldId := range oldTorrentIDs {
t.fixerAddCommand(oldId, "replaced") t.fixerAddCommand(oldId, "replaced")
} }
return
}
}
} }
} }