Surefire way of no dupes
This commit is contained in:
@@ -23,37 +23,42 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
|
||||
expiredFixers := mapset.NewSet[string](t.fixers.Keys()...)
|
||||
for i := range instances {
|
||||
idx := i
|
||||
expiredFixers.Remove(instances[idx].ID)
|
||||
wg.Add(1)
|
||||
_ = t.workerPool.Submit(func() {
|
||||
defer wg.Done()
|
||||
if instances[idx].IsDone() && t.fixers.Has(instances[idx].ID) {
|
||||
if !t.fixers.Has(instances[idx].ID) {
|
||||
infoChan <- t.getMoreInfo(instances[idx])
|
||||
return
|
||||
} else if instances[idx].IsDone() {
|
||||
fixer := instances[idx]
|
||||
torrent, _ := t.fixers.Pop(fixer.ID)
|
||||
t.log.Debugf("Fixer %s is done, let's check if it fixed torrent %s by redownloading", instances[idx].ID, t.GetKey(torrent))
|
||||
brokenFiles := getBrokenFiles(torrent)
|
||||
info, err := t.redownloadTorrent(torrent, "")
|
||||
if err == nil {
|
||||
if info.IsDone() {
|
||||
if t.isStillBroken(info, brokenFiles) {
|
||||
t.log.Warnf("Fixer is done but torrent %s is still broken; let's keep the fixer", t.GetKey(torrent))
|
||||
infoChan <- t.getMoreInfo(fixer)
|
||||
return
|
||||
} else {
|
||||
t.log.Infof("Fixer resolved issues for torrent %s, broken files are repaired", t.GetKey(torrent))
|
||||
}
|
||||
} else {
|
||||
t.log.Warnf("Torrent %s is still not done after redownload; likely the fixer did its job", t.GetKey(torrent))
|
||||
}
|
||||
t.Api.DeleteTorrent(fixer.ID) // delete the fixer
|
||||
if err != nil {
|
||||
t.log.Warnf("Cannot redownload torrent %s after fixer is done: %v", t.GetKey(torrent), err)
|
||||
infoChan <- nil
|
||||
return
|
||||
} else {
|
||||
t.log.Warnf("Cannot redownload torrent %s after fixer is done: %v", t.GetKey(torrent), err)
|
||||
}
|
||||
} else if !t.fixers.Has(instances[idx].ID) {
|
||||
infoChan <- t.getMoreInfo(instances[idx])
|
||||
if info.IsDone() {
|
||||
if t.isStillBroken(info, brokenFiles) {
|
||||
t.log.Warnf("Fixer is done but torrent %s is still broken; let's keep the fixer", t.GetKey(torrent))
|
||||
infoChan <- t.getMoreInfo(fixer)
|
||||
return
|
||||
} else {
|
||||
t.log.Infof("Fixer resolved issues for torrent %s, broken files are repaired", t.GetKey(torrent))
|
||||
}
|
||||
} else {
|
||||
t.log.Warnf("Torrent %s is still not done after redownload; likely the fixer did its job", t.GetKey(torrent))
|
||||
}
|
||||
t.Api.DeleteTorrent(fixer.ID) // delete the fixer
|
||||
infoChan <- nil
|
||||
return
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -62,6 +67,13 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
||||
close(infoChan)
|
||||
t.log.Debugf("Fetched info for %d torrents", len(instances))
|
||||
|
||||
// delete expired fixers
|
||||
expiredFixers.Each(func(fixerID string) bool {
|
||||
t.log.Debugf("Deleting expired fixer %s", fixerID)
|
||||
t.fixers.Remove(fixerID)
|
||||
return false
|
||||
})
|
||||
|
||||
freshKeys := mapset.NewSet[string]()
|
||||
noInfoCount := 0
|
||||
for info := range infoChan {
|
||||
|
||||
Reference in New Issue
Block a user