Fix repairs

This commit is contained in:
Ben Sarmiento
2024-01-16 21:40:07 +01:00
parent 727c694c02
commit 5049320379
3 changed files with 9 additions and 22 deletions

View File

@@ -212,20 +212,6 @@ func (t *TorrentManager) repair(torrent *Torrent) {
})
t.log.Debugf("During repair, zurg found %d broken files for torrent %s", len(brokenFiles), t.GetKey(torrent))
if len(brokenFiles) == 1 && torrent.SelectedFiles.Count() > 2 {
// if we download a single file, it will be named differently
// so we need to download 1 extra file to preserve the name
// this is only relevant if we enable retain_rd_torrent_name
// add the first file link encountered with a prefix of http
t.log.Debugf("Torrent %s has only 1 broken file, adding 1 extra file to preserve the name", t.GetKey(torrent))
for _, file := range torrent.SelectedFiles.Items() {
if strings.HasPrefix(file.Link, "http") {
brokenFiles = append(brokenFiles, *file)
break
}
}
}
if len(brokenFiles) > 0 {
t.log.Infof("Redownloading %dof%d files for torrent %s", len(brokenFiles), torrent.SelectedFiles.Count(), t.GetKey(torrent))
brokenFileIDs := strings.Join(getFileIDs(brokenFiles), ",")
@@ -305,13 +291,13 @@ func (t *TorrentManager) reinsertTorrent(torrent *Torrent, brokenFiles string) b
if info.Progress != 100 {
t.log.Infof("Torrent id=%s is not cached anymore so we have to wait until completion (this should fix the issue already)", info.ID)
t.forRepairs.Add(newTorrentID)
t.onlyForRepair.Add(newTorrentID)
if len(oldTorrentIDs) > 0 {
for _, id := range oldTorrentIDs {
t.Api.DeleteTorrent(id)
}
} else {
t.forRepairs.Add(newTorrentID)
t.onlyForRepair.Add(newTorrentID)
}
return true
}
@@ -324,13 +310,13 @@ func (t *TorrentManager) reinsertTorrent(torrent *Torrent, brokenFiles string) b
}
t.log.Infof("Repair successful id=%s", newTorrentID)
t.forRepairs.Add(newTorrentID)
t.onlyForRepair.Add(newTorrentID)
if len(oldTorrentIDs) > 0 {
for _, id := range oldTorrentIDs {
t.Api.DeleteTorrent(id)
}
} else {
t.forRepairs.Add(newTorrentID)
t.onlyForRepair.Add(newTorrentID)
}
return true
}