Fix repairs

This commit is contained in:
Ben Sarmiento
2024-01-18 20:54:41 +01:00
parent 49fd17c3d4
commit 0a451cccde
4 changed files with 93 additions and 77 deletions

View File

@@ -22,12 +22,23 @@ func (t *TorrentManager) RefreshTorrents() []string {
infoChan := make(chan *Torrent, len(instances))
var wg sync.WaitGroup
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
for i := range instances {
idx := i
wg.Add(1)
_ = t.workerPool.Submit(func() {
defer wg.Done()
infoChan <- t.getMoreInfo(instances[idx])
if instances[idx].Progress == 100 && t.onlyForRepair.Has(instances[idx].ID) {
torrent, _ := t.onlyForRepair.Get(instances[idx].ID)
brokenFiles := getBrokenFiles(torrent)
info, err := t.redownloadTorrent(torrent, "")
if err == nil && info.Progress == 100 && !t.isStillBroken(info, brokenFiles) {
t.onlyForRepair.Remove(instances[idx].ID)
}
infoChan <- nil
} else {
infoChan <- t.getMoreInfo(instances[idx])
}
})
}
@@ -36,19 +47,13 @@ func (t *TorrentManager) RefreshTorrents() []string {
t.log.Debugf("Fetched info for %d torrents", len(instances))
freshKeys := mapset.NewSet[string]()
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
noInfoCount := 0
for info := range infoChan {
if info == nil {
noInfoCount++
continue
}
accessKey := t.GetKey(info)
if t.handleRepairTorrents(info) {
continue
}
if !info.AnyInProgress() {
freshKeys.Add(accessKey)
}