Unrepairable hotfix

This commit is contained in:
Ben Sarmiento
2023-12-08 14:14:58 +01:00
parent 045c31a9f9
commit 62bfa375ca
3 changed files with 12 additions and 11 deletions

View File

@@ -77,8 +77,6 @@ func (t *TorrentManager) RefreshTorrents() []string {
return true
})
t.SetNewLatestState(t.getCurrentState())
return updatedPaths
}
@@ -98,6 +96,7 @@ func (t *TorrentManager) startRefreshJob() {
if t.latestState.equal(checksum) {
continue
}
t.SetNewLatestState(checksum)
t.log.Infof("Detected changes! Refreshing %d torrents", checksum.TotalCount)
updatedPaths := t.RefreshTorrents()

View File

@@ -7,6 +7,8 @@ import (
"time"
)
const EXPIRED_LINK_TOLERANCE_HOURS = 24
func (t *TorrentManager) RepairAll() {
_ = t.repairWorker.Submit(func() {
t.repairAll()
@@ -53,8 +55,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
return
}
expiredLinkTolerance := 24 * time.Hour
if torrent.OlderThanDuration(expiredLinkTolerance) {
if torrent.OlderThanDuration(EXPIRED_LINK_TOLERANCE_HOURS * time.Hour) {
// first solution: reinsert with same selection
if t.reinsertTorrent(torrent, "") {
t.log.Infof("Successfully downloaded torrent %s to repair it", torrent.AccessKey)
@@ -63,7 +64,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
t.log.Warn("Failed to repair by reinserting torrent")
}
} else {
t.log.Infof("Torrent %s is not older than %d hours to be repaired by reinsertion, skipping", torrent.AccessKey, expiredLinkTolerance.Hours())
t.log.Infof("Torrent %s is not older than %d hours to be repaired by reinsertion, skipping", torrent.AccessKey, EXPIRED_LINK_TOLERANCE_HOURS)
}
// second solution: add only the missing files
@@ -74,10 +75,13 @@ func (t *TorrentManager) repair(torrent *Torrent) {
}
})
// if we download a single file, it will be named differently
// so we need to download 1 extra file to preserve the name
// this is only relevant if we enable retain_rd_torrent_name
if len(missingFiles) == 1 && torrent.SelectedFiles.Count() > 1 {
if len(missingFiles) == 1 && torrent.SelectedFiles.Count() == 1 {
t.log.Warnf("Torrent %s is unrepairable, the lone file is expired but still cached in Real-Debrid", torrent.AccessKey)
return
} else if len(missingFiles) == 1 && torrent.SelectedFiles.Count() > 1 {
// if we download a single file, it will be named differently
// so we need to download 1 extra file to preserve the name
// this is only relevant if we enable retain_rd_torrent_name
// add the first file link encountered with a prefix of http
for _, file := range torrent.SelectedFiles.Items() {
if strings.HasPrefix(file.Link, "http") {

View File

@@ -2,7 +2,6 @@ package torrent
import (
stdjson "encoding/json"
"fmt"
"strings"
"time"
@@ -128,7 +127,6 @@ func (t *Torrent) ComputeBiggestFileSize() int64 {
func (t *Torrent) OlderThanDuration(duration time.Duration) bool {
latestAdded, err := time.Parse(time.RFC3339, t.LatestAdded)
if err != nil {
fmt.Println("Error parsing time:", err)
return false
}
return time.Since(latestAdded) > duration