Fixer refactor
This commit is contained in:
@@ -31,6 +31,7 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
|||||||
if instances[idx].IsDone() && t.fixers.Has(instances[idx].ID) {
|
if instances[idx].IsDone() && t.fixers.Has(instances[idx].ID) {
|
||||||
fixer := instances[idx]
|
fixer := instances[idx]
|
||||||
torrent, _ := t.fixers.Pop(fixer.ID)
|
torrent, _ := t.fixers.Pop(fixer.ID)
|
||||||
|
t.log.Debugf("Fixer %s is done, let's check if it fixed torrent %s", instances[idx].ID, t.GetKey(torrent))
|
||||||
brokenFiles := getBrokenFiles(torrent)
|
brokenFiles := getBrokenFiles(torrent)
|
||||||
info, err := t.redownloadTorrent(torrent, "")
|
info, err := t.redownloadTorrent(torrent, "")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
@@ -85,6 +85,14 @@ func (t *TorrentManager) repairAll() {
|
|||||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
if !strings.HasPrefix(file.Link, "http") && file.Link != "unselect" {
|
if !strings.HasPrefix(file.Link, "http") && file.Link != "unselect" {
|
||||||
hasBrokenFiles = true
|
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
|
// get all broken files
|
||||||
brokenFiles := getBrokenFiles(torrent)
|
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
|
// 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, "")
|
info, err := t.redownloadTorrent(torrent, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.log.Warnf("Cannot repair torrent %s", t.GetKey(torrent))
|
t.log.Warnf("Cannot repair torrent %s using repair_method#1", t.GetKey(torrent))
|
||||||
} else if info.Progress != 100 || (info.IsDone() && !t.isStillBroken(info, brokenFiles)) {
|
}
|
||||||
|
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))
|
t.log.Infof("Successfully repaired torrent %s using repair_method#1", t.GetKey(torrent))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -232,10 +246,9 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
|||||||
// second solution: add only the broken files
|
// second solution: add only the broken files
|
||||||
if len(brokenFiles) > 0 {
|
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))
|
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)
|
_, err := t.redownloadTorrent(torrent, brokenFileIDs)
|
||||||
if err != nil {
|
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 {
|
} else {
|
||||||
t.log.Infof("Successfully repaired torrent %s using repair_method#2", t.GetKey(torrent))
|
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)
|
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 {
|
if len(oldTorrentIDs) > 0 {
|
||||||
// only triggered when brokenFiles == ""
|
// only triggered when brokenFiles == ""
|
||||||
for _, id := range oldTorrentIDs {
|
for _, id := range oldTorrentIDs {
|
||||||
|
|||||||
Reference in New Issue
Block a user