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

@@ -210,7 +210,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
} 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.Api.DeleteTorrent(info.ID)
t.fixers.Set(info.ID, torrent)
t.ensureDelete.Add(info.ID)
}
if torrent.UnrepairableReason != "" {
@@ -264,7 +264,7 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, brokenFiles string)
err = t.Api.SelectTorrentFiles(newTorrentID, brokenFiles)
if err != nil {
t.Api.DeleteTorrent(newTorrentID)
t.fixers.Set(newTorrentID, torrent)
t.ensureDelete.Add(newTorrentID)
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)
if err != nil {
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)
}
@@ -288,7 +288,7 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, brokenFiles string)
}
if !isOkStatus {
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)
}
@@ -297,10 +297,11 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, brokenFiles string)
if len(oldTorrentIDs) > 0 {
for _, id := range oldTorrentIDs {
t.Api.DeleteTorrent(id)
t.fixers.Set(id, torrent)
t.ensureDelete.Add(id)
}
} else {
t.fixers.Set(newTorrentID, torrent)
t.ensureDelete.Add(newTorrentID)
}
return info, nil
}
@@ -308,7 +309,7 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, brokenFiles string)
brokenCount := len(strings.Split(brokenFiles, ","))
if len(info.Links) != brokenCount {
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)
}
@@ -316,10 +317,11 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, brokenFiles string)
// only triggered when brokenFiles == ""
for _, id := range oldTorrentIDs {
t.Api.DeleteTorrent(id)
t.fixers.Set(id, torrent)
t.ensureDelete.Add(id)
}
} else {
t.fixers.Set(newTorrentID, torrent)
t.ensureDelete.Add(newTorrentID)
}
return info, nil
}