Hotfix on repairs

This commit is contained in:
Ben Sarmiento
2023-12-06 00:49:11 +01:00
parent de868d97c2
commit 121a28d46f
4 changed files with 44 additions and 38 deletions

View File

@@ -581,13 +581,13 @@ func (t *TorrentManager) repair(torrent *Torrent) {
return
}
// first solution: add the same selection, maybe it can be fixed by reinsertion?
// first solution: reinsert with same selection
if t.reinsertTorrent(torrent, "") {
t.log.Infof("Successfully downloaded torrent %s to repair it", torrent.AccessKey)
return
}
// if all the selected files are missing but there are other streamable files
// second solution: add only the missing files
var missingFiles []File
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
if !strings.HasPrefix(file.Link, "http") {
@@ -629,14 +629,11 @@ func (t *TorrentManager) reinsertTorrent(torrent *Torrent, missingFiles string)
if missingFiles == "" {
tmpSelection := ""
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
if !strings.HasPrefix(file.Link, "http") {
tmpSelection += fmt.Sprintf("%d,", file.ID)
}
tmpSelection += fmt.Sprintf("%d,", file.ID) // select all files
})
if tmpSelection == "" {
return false
}
if len(tmpSelection) > 0 {
return true // nothing to repair
} else {
missingFiles = tmpSelection[:len(tmpSelection)-1]
}
}