Small tweak to repair
This commit is contained in:
@@ -212,13 +212,13 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
||||
// second step: download the broken files
|
||||
if len(brokenFiles) > 0 {
|
||||
t.log.Infof("Repairing by downloading only the %d broken out of %d files of torrent %s", len(brokenFiles), torrent.SelectedFiles.Count(), t.GetKey(torrent))
|
||||
redownloadedTorrent, err := t.redownloadTorrent(torrent, brokenFileIDs)
|
||||
redownloadedInfo, 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
|
||||
}
|
||||
if redownloadedTorrent != nil {
|
||||
t.fixerAddCommand(redownloadedTorrent.ID, "repair")
|
||||
if redownloadedInfo != nil {
|
||||
t.fixerAddCommand(redownloadedInfo.ID, "repaired")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
@@ -347,7 +347,7 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, selection string) (
|
||||
// select files
|
||||
err = t.Api.SelectTorrentFiles(newTorrentID, selection)
|
||||
if err != nil {
|
||||
t.fixerAddCommand(newTorrentID, "delete_failed")
|
||||
t.fixerAddCommand(newTorrentID, "download_failed")
|
||||
return nil, fmt.Errorf("cannot start redownloading: %v", err)
|
||||
}
|
||||
|
||||
@@ -357,7 +357,7 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, selection string) (
|
||||
// see if the torrent is ready
|
||||
info, err := t.Api.GetTorrentInfo(newTorrentID)
|
||||
if err != nil {
|
||||
t.fixerAddCommand(newTorrentID, "delete_failed")
|
||||
t.fixerAddCommand(newTorrentID, "download_failed")
|
||||
return nil, fmt.Errorf("cannot get info on redownloaded torrent %s (id=%s) : %v", t.GetKey(torrent), newTorrentID, err)
|
||||
}
|
||||
|
||||
@@ -372,24 +372,20 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, selection string) (
|
||||
}
|
||||
}
|
||||
if !isOkStatus {
|
||||
t.fixerAddCommand(newTorrentID, "delete_failed")
|
||||
t.fixerAddCommand(newTorrentID, "download_failed")
|
||||
return nil, fmt.Errorf("the redownloaded torrent %s (id=%s) is in error state: %s", t.GetKey(torrent), newTorrentID, info.Status)
|
||||
}
|
||||
|
||||
// check if incorrect number of links
|
||||
selectionCount := len(strings.Split(selection, ","))
|
||||
if info.Progress == 100 && len(info.Links) != selectionCount {
|
||||
t.fixerAddCommand(newTorrentID, "delete_failed")
|
||||
t.fixerAddCommand(newTorrentID, "download_failed")
|
||||
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), selectionCount)
|
||||
}
|
||||
|
||||
// looks like it's fixed
|
||||
|
||||
if len(oldTorrentIDs) > 0 {
|
||||
// replace the old torrent (empty selection)
|
||||
for _, id := range oldTorrentIDs {
|
||||
t.fixerAddCommand(id, "delete_replaced")
|
||||
}
|
||||
// looks like it's fixed even if it's not done yet
|
||||
for _, id := range oldTorrentIDs {
|
||||
t.fixerAddCommand(id, "replaced")
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user