Fix duplication
This commit is contained in:
@@ -29,6 +29,7 @@ type TorrentManager struct {
|
|||||||
DownloadMap cmap.ConcurrentMap[string, *realdebrid.Download]
|
DownloadMap cmap.ConcurrentMap[string, *realdebrid.Download]
|
||||||
fixers cmap.ConcurrentMap[string, *Torrent]
|
fixers cmap.ConcurrentMap[string, *Torrent]
|
||||||
repairs mapset.Set[string]
|
repairs mapset.Set[string]
|
||||||
|
ensureDelete mapset.Set[string]
|
||||||
allAccessKeys mapset.Set[string]
|
allAccessKeys mapset.Set[string]
|
||||||
latestState *LibraryState
|
latestState *LibraryState
|
||||||
requiredVersion string
|
requiredVersion string
|
||||||
@@ -49,6 +50,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w
|
|||||||
DownloadMap: cmap.New[*realdebrid.Download](),
|
DownloadMap: cmap.New[*realdebrid.Download](),
|
||||||
fixers: cmap.New[*Torrent](),
|
fixers: cmap.New[*Torrent](),
|
||||||
repairs: mapset.NewSet[string](),
|
repairs: mapset.NewSet[string](),
|
||||||
|
ensureDelete: mapset.NewSet[string](),
|
||||||
allAccessKeys: mapset.NewSet[string](),
|
allAccessKeys: mapset.NewSet[string](),
|
||||||
latestState: &LibraryState{},
|
latestState: &LibraryState{},
|
||||||
requiredVersion: "24.01.2024",
|
requiredVersion: "24.01.2024",
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
|||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
|
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
|
||||||
expiredFixers := mapset.NewSet[string](t.fixers.Keys()...)
|
expiredFixers := t.ensureDelete.Clone()
|
||||||
for i := range instances {
|
for i := range instances {
|
||||||
idx := i
|
idx := i
|
||||||
expiredFixers.Remove(instances[idx].ID)
|
expiredFixers.Remove(instances[idx].ID)
|
||||||
@@ -71,6 +71,17 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
|||||||
expiredFixers.Each(func(fixerID string) bool {
|
expiredFixers.Each(func(fixerID string) bool {
|
||||||
t.log.Debugf("Deleting expired fixer %s", fixerID)
|
t.log.Debugf("Deleting expired fixer %s", fixerID)
|
||||||
t.fixers.Remove(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
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
|||||||
} else if info != nil && info.ID != "" {
|
} else if info != nil && info.ID != "" {
|
||||||
t.log.Warnf("Torrent %s is still broken after repair_method#1, cleaning up (deleting ID=%s)", t.GetKey(torrent), info.ID)
|
t.log.Warnf("Torrent %s is still broken after repair_method#1, cleaning up (deleting ID=%s)", t.GetKey(torrent), info.ID)
|
||||||
t.Api.DeleteTorrent(info.ID)
|
t.Api.DeleteTorrent(info.ID)
|
||||||
t.fixers.Set(info.ID, torrent)
|
t.ensureDelete.Add(info.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if torrent.UnrepairableReason != "" {
|
if torrent.UnrepairableReason != "" {
|
||||||
@@ -264,7 +264,7 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, brokenFiles string)
|
|||||||
err = t.Api.SelectTorrentFiles(newTorrentID, brokenFiles)
|
err = t.Api.SelectTorrentFiles(newTorrentID, brokenFiles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Api.DeleteTorrent(newTorrentID)
|
t.Api.DeleteTorrent(newTorrentID)
|
||||||
t.fixers.Set(newTorrentID, torrent)
|
t.ensureDelete.Add(newTorrentID)
|
||||||
return nil, fmt.Errorf("cannot start redownloading: %v", err)
|
return nil, fmt.Errorf("cannot start redownloading: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,7 +272,7 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, brokenFiles string)
|
|||||||
info, err := t.Api.GetTorrentInfo(newTorrentID)
|
info, err := t.Api.GetTorrentInfo(newTorrentID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Api.DeleteTorrent(newTorrentID)
|
t.Api.DeleteTorrent(newTorrentID)
|
||||||
t.fixers.Set(newTorrentID, torrent)
|
t.ensureDelete.Add(newTorrentID)
|
||||||
return nil, fmt.Errorf("cannot get info on redownloaded torrent %s (id=%s) : %v", t.GetKey(torrent), newTorrentID, err)
|
return nil, fmt.Errorf("cannot get info on redownloaded torrent %s (id=%s) : %v", t.GetKey(torrent), newTorrentID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,7 +288,7 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, brokenFiles string)
|
|||||||
}
|
}
|
||||||
if !isOkStatus {
|
if !isOkStatus {
|
||||||
t.Api.DeleteTorrent(newTorrentID)
|
t.Api.DeleteTorrent(newTorrentID)
|
||||||
t.fixers.Set(newTorrentID, torrent)
|
t.ensureDelete.Add(newTorrentID)
|
||||||
return nil, fmt.Errorf("the redownloaded torrent %s (id=%s) is in error state: %s", t.GetKey(torrent), newTorrentID, info.Status)
|
return nil, fmt.Errorf("the redownloaded torrent %s (id=%s) is in error state: %s", t.GetKey(torrent), newTorrentID, info.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,10 +297,11 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, brokenFiles string)
|
|||||||
if len(oldTorrentIDs) > 0 {
|
if len(oldTorrentIDs) > 0 {
|
||||||
for _, id := range oldTorrentIDs {
|
for _, id := range oldTorrentIDs {
|
||||||
t.Api.DeleteTorrent(id)
|
t.Api.DeleteTorrent(id)
|
||||||
t.fixers.Set(id, torrent)
|
t.ensureDelete.Add(id)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
t.fixers.Set(newTorrentID, torrent)
|
t.fixers.Set(newTorrentID, torrent)
|
||||||
|
t.ensureDelete.Add(newTorrentID)
|
||||||
}
|
}
|
||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
@@ -308,7 +309,7 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, brokenFiles string)
|
|||||||
brokenCount := len(strings.Split(brokenFiles, ","))
|
brokenCount := len(strings.Split(brokenFiles, ","))
|
||||||
if len(info.Links) != brokenCount {
|
if len(info.Links) != brokenCount {
|
||||||
t.Api.DeleteTorrent(newTorrentID)
|
t.Api.DeleteTorrent(newTorrentID)
|
||||||
t.fixers.Set(newTorrentID, torrent)
|
t.ensureDelete.Add(newTorrentID)
|
||||||
return nil, fmt.Errorf("it did not fix the issue for %s (id=%s), only got %d files but we need %d, undoing", t.GetKey(torrent), info.ID, len(info.Links), brokenCount)
|
return nil, fmt.Errorf("it did not fix the issue for %s (id=%s), only got %d files but we need %d, undoing", t.GetKey(torrent), info.ID, len(info.Links), brokenCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,10 +317,11 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, brokenFiles string)
|
|||||||
// only triggered when brokenFiles == ""
|
// only triggered when brokenFiles == ""
|
||||||
for _, id := range oldTorrentIDs {
|
for _, id := range oldTorrentIDs {
|
||||||
t.Api.DeleteTorrent(id)
|
t.Api.DeleteTorrent(id)
|
||||||
t.fixers.Set(id, torrent)
|
t.ensureDelete.Add(id)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
t.fixers.Set(newTorrentID, torrent)
|
t.fixers.Set(newTorrentID, torrent)
|
||||||
|
t.ensureDelete.Add(newTorrentID)
|
||||||
}
|
}
|
||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user