Fix duplication

This commit is contained in:
Ben Sarmiento
2024-01-24 12:23:50 +01:00
parent 2b6f0f95a8
commit 52a31abe35
3 changed files with 23 additions and 8 deletions

View File

@@ -23,7 +23,7 @@ func (t *TorrentManager) RefreshTorrents() []string {
var wg sync.WaitGroup
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
expiredFixers := mapset.NewSet[string](t.fixers.Keys()...)
expiredFixers := t.ensureDelete.Clone()
for i := range instances {
idx := i
expiredFixers.Remove(instances[idx].ID)
@@ -71,6 +71,17 @@ func (t *TorrentManager) RefreshTorrents() []string {
expiredFixers.Each(func(fixerID string) bool {
t.log.Debugf("Deleting expired fixer %s", fixerID)
t.fixers.Remove(fixerID)
t.ensureDelete.Remove(fixerID)
return false
})
// ensure delete
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
t.ensureDelete.Each(func(fixerID string) bool {
if torrent, exists := infoCache.Get(fixerID); exists && torrent.AnyInProgress() {
return false
}
t.log.Debugf("Ensuring that torrent id=%s is deleted", fixerID)
t.Api.DeleteTorrent(fixerID)
return false
})