100 broken files at a time
This commit is contained in:
@@ -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())
|
||||||
}
|
return
|
||||||
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, oldId := range oldTorrentIDs {
|
||||||
|
t.fixerAddCommand(oldId, "replaced")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user