Remove link on repair

This commit is contained in:
Ben Sarmiento
2024-01-26 12:59:00 +01:00
parent 4852b93c67
commit 58b0b8b917
2 changed files with 32 additions and 33 deletions

View File

@@ -35,16 +35,40 @@ func (t *TorrentManager) repairAll() {
return return
} }
// save the broken files to the file cache
// broken files are also added when trying to open a file
if torrent.BrokenLinks.Cardinality() > 0 {
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
torrent.DownloadedIDs.Each(func(id string) bool {
info, _ := infoCache.Get(id)
hasBrokenFiles := false
info.SelectedFiles.IterCb(func(_ string, file *File) {
torrent.BrokenLinks.Each(func(brokenLink string) bool {
if file.Link == brokenLink {
hasBrokenFiles = true
file.Link = ""
return true
}
return false
})
})
if hasBrokenFiles {
info.BrokenLinks = torrent.BrokenLinks
t.writeTorrentToFile(id, info)
}
return false
})
}
// check 2: for broken files // check 2: for broken files
hasBrokenFiles := false brokenFileIDs := mapset.NewSet[int]()
torrent.SelectedFiles.IterCb(func(_ string, file *File) { torrent.SelectedFiles.IterCb(func(_ string, file *File) {
if !strings.HasPrefix(file.Link, "http") && file.Link != "unselect" { if !strings.HasPrefix(file.Link, "http") && file.Link != "unselect" {
hasBrokenFiles = true brokenFileIDs.Add(file.ID)
return
} }
}) })
if hasBrokenFiles { if brokenFileIDs.Cardinality() > 0 {
t.log.Debugf("Torrent %s has broken files, adding to repair list", t.GetKey(torrent)) t.log.Debugf("Torrent %s has broken files (ids=%v), adding to repair list", t.GetKey(torrent), brokenFileIDs.ToSlice())
toRepair.Add(torrent) toRepair.Add(torrent)
return return
} }
@@ -80,31 +104,6 @@ func (t *TorrentManager) Repair(torrent *Torrent) {
t.repairs.Add(t.GetKey(torrent)) t.repairs.Add(t.GetKey(torrent))
// save the broken files to the file cache
// broken files are also added when trying to open a file
if torrent.BrokenLinks.Cardinality() > 0 {
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
torrent.DownloadedIDs.Each(func(id string) bool {
info, _ := infoCache.Get(id)
hasBrokenFiles := false
info.SelectedFiles.IterCb(func(_ string, file *File) {
torrent.BrokenLinks.Each(func(brokenLink string) bool {
if file.Link == brokenLink {
hasBrokenFiles = true
file.Link = ""
return true
}
return false
})
})
if hasBrokenFiles {
info.BrokenLinks = torrent.BrokenLinks
t.writeTorrentToFile(id, info)
}
return false
})
}
t.log.Infof("Attempting repair for torrent %s", t.GetKey(torrent)) t.log.Infof("Attempting repair for torrent %s", t.GetKey(torrent))
// blocks for approx 45 minutes if active torrents are full // blocks for approx 45 minutes if active torrents are full

View File

@@ -55,7 +55,7 @@ func (dl *Downloader) DownloadFile(directory, torrentName, fileName string, resp
if unrestrict == nil { if unrestrict == nil {
log.Warnf("File %s cannot be unrestricted (link=%s)", fileName, link) log.Warnf("File %s cannot be unrestricted (link=%s)", fileName, link)
torrent.BrokenLinks.Add(file.Link) torrent.BrokenLinks.Add(file.Link)
file.Link = "repair" // file.Link = "repair"
if cfg.EnableRepair() { if cfg.EnableRepair() {
torMgr.SetNewLatestState(intTor.LibraryState{}) torMgr.SetNewLatestState(intTor.LibraryState{})
} else { } else {
@@ -167,7 +167,7 @@ func (dl *Downloader) streamFileToResponse(torrent *intTor.Torrent, file *intTor
log.Warnf("Cannot download file %s: %v", unrestrict.Download, err) log.Warnf("Cannot download file %s: %v", unrestrict.Download, err)
if file != nil && unrestrict.Streamable == 1 { if file != nil && unrestrict.Streamable == 1 {
torrent.BrokenLinks.Add(file.Link) torrent.BrokenLinks.Add(file.Link)
file.Link = "repair" // file.Link = "repair"
if cfg.EnableRepair() && torrent != nil { if cfg.EnableRepair() && torrent != nil {
torMgr.SetNewLatestState(intTor.LibraryState{}) torMgr.SetNewLatestState(intTor.LibraryState{})
} else { } else {
@@ -184,7 +184,7 @@ func (dl *Downloader) streamFileToResponse(torrent *intTor.Torrent, file *intTor
if file != nil && unrestrict.Streamable == 1 { if file != nil && unrestrict.Streamable == 1 {
log.Warnf("Received a %s status code for file %s", download.Status, file.Path) log.Warnf("Received a %s status code for file %s", download.Status, file.Path)
torrent.BrokenLinks.Add(file.Link) torrent.BrokenLinks.Add(file.Link)
file.Link = "repair" // file.Link = "repair"
if cfg.EnableRepair() && torrent != nil { if cfg.EnableRepair() && torrent != nil {
torMgr.SetNewLatestState(intTor.LibraryState{}) torMgr.SetNewLatestState(intTor.LibraryState{})
} else { } else {