Identify broken links properly

This commit is contained in:
Ben Sarmiento
2024-01-11 07:43:27 +01:00
parent 628e3d6345
commit cc37a92d75
6 changed files with 29 additions and 22 deletions

View File

@@ -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)
}
})