Delete in progress fixers

This commit is contained in:
Ben Sarmiento
2024-02-05 12:59:55 +01:00
parent eb9d91f8de
commit 58332a354b
4 changed files with 11 additions and 11 deletions

View File

@@ -214,7 +214,7 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
}
torrent.DownloadedIDs = mapset.NewSet[string]()
torrent.InProgressIDs = mapset.NewSet[string]()
if info.IsDone() {
if info.Progress == 100 {
torrent.DownloadedIDs.Add(info.ID)
} else {
torrent.InProgressIDs.Add(info.ID)

View File

@@ -106,7 +106,6 @@ func (t *TorrentManager) repairAll(torrent *Torrent) {
}
})
if brokenFileIDs.Cardinality() > 0 {
t.log.Debugf("Torrent %s has %d broken files (ids=%v), adding to repair list", t.GetKey(torrent), brokenFileIDs.Cardinality(), brokenFileIDs.ToSlice())
toRepair.Add(torrent)
return
}
@@ -166,18 +165,19 @@ func (t *TorrentManager) repair(torrent *Torrent) {
// get all broken files
brokenFiles := getBrokenFiles(torrent)
t.log.Debugf("Torrent %s has %d broken files (total is %d)", t.GetKey(torrent), len(brokenFiles), torrent.SelectedFiles.Count())
brokenFileIDs := getFileIDs(brokenFiles)
t.log.Debugf("Torrent %s has %d broken files (ids=%s; total is %d), repairing by redownloading", t.GetKey(torrent), len(brokenFiles), brokenFileIDs, torrent.SelectedFiles.Count())
// first step: redownload the whole torrent
t.log.Debugf("Repairing torrent %s by redownloading", t.GetKey(torrent))
info, err := t.redownloadTorrent(torrent, "") // reinsert the torrent, passing ""
if err != nil {
t.log.Warnf("Cannot repair torrent %s by redownloading (error=%s)", t.GetKey(torrent), err.Error())
} else if info != nil && info.Progress != 100 {
t.log.Infof("Torrent %s is still in progress after redownloading but it should be repaired once done", t.GetKey(torrent))
torrent.InProgressIDs.Add(info.ID)
t.saveTorrentChangesToDisk(torrent, nil)
t.log.Infof("Torrent %s (files=%s) is still in progress after redownloading but it should be repaired once done", t.GetKey(torrent), brokenFileIDs)
return
} else if info != nil && info.IsDone() && !t.isStillBroken(info, brokenFiles) {
} else if info != nil && info.Progress == 100 && !t.isStillBroken(info, brokenFiles) {
selectedFiles := getSelectedFiles(info)
torrent.SelectedFiles.IterCb(func(_ string, oldFile *File) {
for _, newFile := range selectedFiles {
@@ -190,7 +190,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
})
torrent.DownloadedIDs.Add(info.ID)
t.saveTorrentChangesToDisk(torrent, nil)
t.log.Infof("Successfully repaired torrent %s by redownloading", t.GetKey(torrent))
t.log.Infof("Successfully repaired torrent %s (files=%s) by redownloading", t.GetKey(torrent), brokenFileIDs)
return
}