Prevent race condition with downloaded id
This commit is contained in:
@@ -21,8 +21,8 @@ func (t *TorrentManager) fixerAddCommand(trigger, command string) {
|
||||
t.writeFixersToFile()
|
||||
}
|
||||
|
||||
func (t *TorrentManager) handleFixers(instances []realdebrid.Torrent) {
|
||||
t.log.Debugf("Handling fixers - %d left", t.fixers.Count())
|
||||
func (t *TorrentManager) processFixers(instances []realdebrid.Torrent) {
|
||||
t.log.Debugf("Processing fixers (%d left)", t.fixers.Count())
|
||||
var toDelete []string
|
||||
var toRedownload []*Torrent
|
||||
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
|
||||
@@ -56,25 +56,34 @@ func (t *TorrentManager) handleFixers(instances []realdebrid.Torrent) {
|
||||
infoCache.Remove(id)
|
||||
t.deleteTorrentFile(id)
|
||||
}
|
||||
|
||||
for _, torrent := range toRedownload {
|
||||
t.redownloadTorrent(torrent, "")
|
||||
}
|
||||
// remove expired fixers
|
||||
var expired []string
|
||||
t.fixers.IterCb(func(trigger string, command string) {
|
||||
if infoCache.Has(trigger) {
|
||||
return
|
||||
}
|
||||
expired = append(expired, trigger)
|
||||
})
|
||||
for _, trigger := range expired {
|
||||
t.log.Debugf("Removing expired fixer id=%s", trigger)
|
||||
t.fixers.Remove(trigger)
|
||||
}
|
||||
|
||||
t.writeFixersToFile()
|
||||
|
||||
t.log.Debugf("Finished handling fixers")
|
||||
t.log.Debugf("Finished processing fixers")
|
||||
}
|
||||
|
||||
func (t *TorrentManager) removeExpiredFixers(instances []realdebrid.Torrent) {
|
||||
fixers := t.fixers.Keys()
|
||||
if len(fixers) == 0 {
|
||||
return
|
||||
}
|
||||
for _, fixerID := range fixers {
|
||||
found := false
|
||||
for _, instance := range instances {
|
||||
if instance.ID == fixerID {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.log.Debugf("Removing expired fixer id=%s", fixerID)
|
||||
t.fixers.Remove(fixerID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TorrentManager) writeFixersToFile() {
|
||||
|
||||
Reference in New Issue
Block a user