Identify broken links properly
This commit is contained in:
@@ -102,26 +102,16 @@ func (t *TorrentManager) repairAll() {
|
||||
|
||||
func (t *TorrentManager) Repair(torrent *Torrent) {
|
||||
// save the broken files to the file cache
|
||||
var brokenFileIDs []int
|
||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||
if file.Link == "repair" {
|
||||
brokenFileIDs = append(brokenFileIDs, file.ID)
|
||||
}
|
||||
})
|
||||
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
||||
info, _ := infoCache.Get(id)
|
||||
info.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||
found := false
|
||||
for _, brokenFileID := range brokenFileIDs {
|
||||
if file.ID == brokenFileID {
|
||||
found = true
|
||||
break
|
||||
torrent.BrokenLinks.Each(func(link string) bool {
|
||||
if file.Link == link {
|
||||
file.Link = "repair"
|
||||
}
|
||||
}
|
||||
if found {
|
||||
file.Link = "unselect"
|
||||
}
|
||||
return file.Link == link
|
||||
})
|
||||
})
|
||||
t.writeTorrentToFile(id, info, false)
|
||||
return false
|
||||
@@ -221,7 +211,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
||||
// second solution: add only the broken files
|
||||
var brokenFiles []File
|
||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||
if file.Link == "repair" || file.Link == "" {
|
||||
if !strings.HasPrefix(file.Link, "http") && file.Link != "unselect" {
|
||||
brokenFiles = append(brokenFiles, *file)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user