Fixer refactor
This commit is contained in:
@@ -85,6 +85,14 @@ func (t *TorrentManager) repairAll() {
|
||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||
if !strings.HasPrefix(file.Link, "http") && file.Link != "unselect" {
|
||||
hasBrokenFiles = true
|
||||
return
|
||||
}
|
||||
if !isCached && strings.HasPrefix(file.Link, "http") {
|
||||
unrestrict := t.UnrestrictUntilOk(file.Link)
|
||||
if unrestrict == nil || file.Bytes != unrestrict.Filesize {
|
||||
hasBrokenFiles = true
|
||||
return
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -217,14 +225,20 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
||||
|
||||
// get all broken files
|
||||
brokenFiles := getBrokenFiles(torrent)
|
||||
t.log.Debugf("During repair, zurg found %d broken files for torrent %s", len(brokenFiles), t.GetKey(torrent))
|
||||
fileIDs := getFileIDs(brokenFiles)
|
||||
brokenFileIDs := strings.Join(fileIDs, ",")
|
||||
|
||||
// first solution: reinsert and see if the broken file is now working
|
||||
t.log.Debugf("repair_method#1: Trying to redownload torrent %s to repair it", t.GetKey(torrent))
|
||||
t.log.Debugf("repair_method#1: Trying to redownload torrent %s to repair files (%s)", t.GetKey(torrent), brokenFileIDs)
|
||||
info, err := t.redownloadTorrent(torrent, "")
|
||||
if err != nil {
|
||||
t.log.Warnf("Cannot repair torrent %s", t.GetKey(torrent))
|
||||
} else if info.Progress != 100 || (info.IsDone() && !t.isStillBroken(info, brokenFiles)) {
|
||||
t.log.Warnf("Cannot repair torrent %s using repair_method#1", t.GetKey(torrent))
|
||||
}
|
||||
if info != nil && info.Progress != 100 {
|
||||
t.log.Infof("Redownloading torrent %s after repair_method#1, it should work once done", t.GetKey(torrent))
|
||||
return
|
||||
}
|
||||
if info != nil && info.IsDone() && !t.isStillBroken(info, brokenFiles) {
|
||||
t.log.Infof("Successfully repaired torrent %s using repair_method#1", t.GetKey(torrent))
|
||||
return
|
||||
}
|
||||
@@ -232,10 +246,9 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
||||
// second solution: add only the broken files
|
||||
if len(brokenFiles) > 0 {
|
||||
t.log.Infof("repair_method#2: Redownloading %dof%d broken files for torrent %s", len(brokenFiles), torrent.SelectedFiles.Count(), t.GetKey(torrent))
|
||||
brokenFileIDs := strings.Join(getFileIDs(brokenFiles), ",")
|
||||
_, err := t.redownloadTorrent(torrent, brokenFileIDs)
|
||||
if err != nil {
|
||||
t.log.Warnf("Cannot repair torrent %s", t.GetKey(torrent))
|
||||
t.log.Warnf("Cannot repair torrent %s using repair_method#2", t.GetKey(torrent))
|
||||
} else {
|
||||
t.log.Infof("Successfully repaired torrent %s using repair_method#2", t.GetKey(torrent))
|
||||
}
|
||||
@@ -323,7 +336,6 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, brokenFiles string)
|
||||
return nil, fmt.Errorf("it did not fix the issue for %s (id=%s), only got %d files but we need %d, undoing", t.GetKey(torrent), info.ID, len(info.Links), brokenCount)
|
||||
}
|
||||
|
||||
t.log.Infof("Redownload successful %s (id=%s)", t.GetKey(torrent), newTorrentID)
|
||||
if len(oldTorrentIDs) > 0 {
|
||||
// only triggered when brokenFiles == ""
|
||||
for _, id := range oldTorrentIDs {
|
||||
|
||||
Reference in New Issue
Block a user