Check for other broken files when repairing

This commit is contained in:
Ben Sarmiento
2024-05-25 01:51:00 +02:00
parent 0a086d7a14
commit abb80b4257
3 changed files with 12 additions and 4 deletions

View File

@@ -234,7 +234,7 @@ func (t *TorrentManager) writeInfoToFile(info *realdebrid.TorrentInfo) {
return return
} }
t.log.Debugf("Saved torrent %s to info file", info.ID) // t.log.Debugf("Saved torrent %s to info file", info.ID)
} }
func (t *TorrentManager) readInfoFromFile(torrentID string) *realdebrid.TorrentInfo { func (t *TorrentManager) readInfoFromFile(torrentID string) *realdebrid.TorrentInfo {

View File

@@ -159,7 +159,7 @@ func (t *TorrentManager) refreshTorrents() []string {
return false return false
}) })
existingIDs.Difference(freshIDs).Each(func(id string) bool { existingIDs.Difference(freshIDs).Each(func(id string) bool {
t.log.Infof("Deleting stale info file %s", id) // t.log.Infof("Deleting stale info file %s", id)
t.deleteInfoFile(id) t.deleteInfoFile(id)
return false return false
}) })
@@ -498,8 +498,6 @@ func (t *TorrentManager) persistBins() {
_, err = file.Write(jsonData) _, err = file.Write(jsonData)
if err != nil { if err != nil {
t.log.Errorf("Failed to write to bins.json file: %v", err) t.log.Errorf("Failed to write to bins.json file: %v", err)
} else {
t.log.Debug("Successfully saved bins to file")
} }
} }

View File

@@ -173,6 +173,16 @@ func (t *TorrentManager) repair(torrent *Torrent) {
return return
} }
// check for other broken files
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
if !file.State.Is("ok_file") {
return
}
if t.UnrestrictFileUntilOk(file) == nil {
file.State.Event(context.Background(), "break_file")
}
})
brokenFiles, allBroken := getBrokenFiles(torrent) brokenFiles, allBroken := getBrokenFiles(torrent)
// first step: redownload the whole torrent // first step: redownload the whole torrent