Reimplement deletes and marking files as broken
This commit is contained in:
@@ -101,7 +101,7 @@ func (t *TorrentManager) repairAll(torrent *Torrent) {
|
||||
// check 1: for broken files
|
||||
brokenFileIDs := mapset.NewSet[int]()
|
||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||
if !strings.HasPrefix(file.Link, "http") && file.Link != "unselect" {
|
||||
if file.IsBroken && !file.IsDeleted {
|
||||
brokenFileIDs.Add(file.ID)
|
||||
}
|
||||
})
|
||||
@@ -337,7 +337,6 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, selection string) (
|
||||
err = t.Api.SelectTorrentFiles(newTorrentID, selection)
|
||||
if err != nil {
|
||||
t.Api.DeleteTorrent(newTorrentID)
|
||||
t.deleteOnceDone.Add(newTorrentID)
|
||||
return nil, fmt.Errorf("cannot start redownloading: %v", err)
|
||||
}
|
||||
|
||||
@@ -348,7 +347,6 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, selection string) (
|
||||
info, err := t.Api.GetTorrentInfo(newTorrentID)
|
||||
if err != nil {
|
||||
t.Api.DeleteTorrent(newTorrentID)
|
||||
t.deleteOnceDone.Add(newTorrentID)
|
||||
return nil, fmt.Errorf("cannot get info on redownloaded torrent %s (id=%s) : %v", t.GetKey(torrent), newTorrentID, err)
|
||||
}
|
||||
|
||||
@@ -364,7 +362,6 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, selection string) (
|
||||
}
|
||||
if !isOkStatus {
|
||||
t.Api.DeleteTorrent(newTorrentID)
|
||||
t.deleteOnceDone.Add(newTorrentID)
|
||||
return nil, fmt.Errorf("the redownloaded torrent %s (id=%s) is in error state: %s", t.GetKey(torrent), newTorrentID, info.Status)
|
||||
}
|
||||
|
||||
@@ -372,7 +369,6 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, selection string) (
|
||||
selectionCount := len(strings.Split(selection, ","))
|
||||
if info.Progress == 100 && len(info.Links) != selectionCount {
|
||||
t.Api.DeleteTorrent(newTorrentID)
|
||||
t.deleteOnceDone.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), selectionCount)
|
||||
}
|
||||
|
||||
@@ -384,13 +380,11 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, selection string) (
|
||||
for _, id := range oldTorrentIDs {
|
||||
torrent.DownloadedIDs.Remove(id)
|
||||
t.Api.DeleteTorrent(id)
|
||||
t.deleteOnceDone.Add(id)
|
||||
infoCache.Remove(id)
|
||||
}
|
||||
} else {
|
||||
// it's a fixer
|
||||
t.fixers.Set(newTorrentID, torrent)
|
||||
t.deleteOnceDone.Add(newTorrentID)
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
@@ -455,11 +449,11 @@ func (t *TorrentManager) markAsUnfixable(torrent *Torrent, reason string) {
|
||||
})
|
||||
}
|
||||
|
||||
// getBrokenFiles returns the files that are not http links and not unselect
|
||||
// getBrokenFiles returns the files that are not http links and not deleted
|
||||
func getBrokenFiles(torrent *Torrent) []*File {
|
||||
var brokenFiles []*File
|
||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||
if !strings.HasPrefix(file.Link, "http") && file.Link != "unselect" {
|
||||
if file.IsBroken && !file.IsDeleted {
|
||||
brokenFiles = append(brokenFiles, file)
|
||||
}
|
||||
})
|
||||
@@ -515,7 +509,6 @@ func (t *TorrentManager) handleFixers(fixer realdebrid.Torrent) *Torrent {
|
||||
if torrent == nil {
|
||||
t.log.Warnf("repair_method#2: Fixer for %s (id=%s) is done but torrent has been deleted, deleting fixer...", fixer.Name, fixer.ID)
|
||||
t.Api.DeleteTorrent(fixer.ID)
|
||||
t.deleteOnceDone.Add(fixer.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -542,7 +535,6 @@ func (t *TorrentManager) handleFixers(fixer realdebrid.Torrent) *Torrent {
|
||||
} else {
|
||||
t.log.Warnf("repair_method#2: Fixer is done but torrent %s is still broken; let's keep the fixer", t.GetKey(torrent))
|
||||
t.Api.DeleteTorrent(info.ID)
|
||||
t.deleteOnceDone.Add(fixer.ID)
|
||||
return t.getMoreInfo(fixer)
|
||||
}
|
||||
} else {
|
||||
@@ -550,7 +542,6 @@ func (t *TorrentManager) handleFixers(fixer realdebrid.Torrent) *Torrent {
|
||||
}
|
||||
|
||||
t.Api.DeleteTorrent(fixer.ID) // delete the fixer
|
||||
t.deleteOnceDone.Add(fixer.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user