Torrent repair fix
This commit is contained in:
@@ -94,6 +94,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
|||||||
// so we need to download 1 extra file to preserve the name
|
// so we need to download 1 extra file to preserve the name
|
||||||
// this is only relevant if we enable retain_rd_torrent_name
|
// this is only relevant if we enable retain_rd_torrent_name
|
||||||
// add the first file link encountered with a prefix of http
|
// add the first file link encountered with a prefix of http
|
||||||
|
t.log.Debugf("Torrent %s has only 1 missing file, adding 1 extra file to preserve the name", torrent.AccessKey)
|
||||||
for _, file := range torrent.SelectedFiles.Items() {
|
for _, file := range torrent.SelectedFiles.Items() {
|
||||||
if strings.HasPrefix(file.Link, "http") {
|
if strings.HasPrefix(file.Link, "http") {
|
||||||
missingFiles = append(missingFiles, *file)
|
missingFiles = append(missingFiles, *file)
|
||||||
@@ -102,17 +103,9 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(missingFiles) > 0 {
|
if len(missingFiles) > 0 {
|
||||||
t.log.Infof("Redownloading in multiple batches the %d missing files for torrent %s", len(missingFiles), torrent.AccessKey)
|
t.log.Infof("Redownloading the %d missing files for torrent %s", len(missingFiles), torrent.AccessKey)
|
||||||
// if not, last resort: add only the missing files but do it in 2 batches
|
missingFileIDs := strings.Join(getFileIDs(missingFiles), ",")
|
||||||
half := len(missingFiles) / 2
|
t.reinsertTorrent(torrent, missingFileIDs)
|
||||||
missingFiles1 := strings.Join(getFileIDs(missingFiles[:half]), ",")
|
|
||||||
missingFiles2 := strings.Join(getFileIDs(missingFiles[half:]), ",")
|
|
||||||
if missingFiles1 != "" {
|
|
||||||
t.reinsertTorrent(torrent, missingFiles1)
|
|
||||||
}
|
|
||||||
if missingFiles2 != "" {
|
|
||||||
t.reinsertTorrent(torrent, missingFiles2)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
t.log.Warnf("Torrent %s has no missing files to repair", torrent.AccessKey)
|
t.log.Warnf("Torrent %s has no missing files to repair", torrent.AccessKey)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user