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))
oldTorrentIDs := torrent.DownloadedIDs.Union(torrent.InProgressIDs).ToSlice()
// divide the broken files into 2 groups
group1 := make([]*File, 0)
group2 := make([]*File, 0)
for idx, file := range brokenFiles {
if idx%2 == 0 {
group1 = append(group1, file)
} else {
group2 = append(group2, file)
}
}
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
}
if redownloadedInfo1 != nil {
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())
return
}
if redownloadedInfo2 != nil {
for _, oldId := range oldTorrentIDs {
t.fixerAddCommand(oldId, "replaced")
group := make([]*File, 0)
for _, file := range brokenFiles {
group = append(group, file)
if len(group) == 100 {
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
}
group = make([]*File, 0)
}
}
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
}
}
for _, oldId := range oldTorrentIDs {
t.fixerAddCommand(oldId, "replaced")
}
}
}