Unrepairable hotfix
This commit is contained in:
@@ -77,8 +77,6 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
|||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
t.SetNewLatestState(t.getCurrentState())
|
|
||||||
|
|
||||||
return updatedPaths
|
return updatedPaths
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +96,7 @@ func (t *TorrentManager) startRefreshJob() {
|
|||||||
if t.latestState.equal(checksum) {
|
if t.latestState.equal(checksum) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
t.SetNewLatestState(checksum)
|
||||||
t.log.Infof("Detected changes! Refreshing %d torrents", checksum.TotalCount)
|
t.log.Infof("Detected changes! Refreshing %d torrents", checksum.TotalCount)
|
||||||
|
|
||||||
updatedPaths := t.RefreshTorrents()
|
updatedPaths := t.RefreshTorrents()
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const EXPIRED_LINK_TOLERANCE_HOURS = 24
|
||||||
|
|
||||||
func (t *TorrentManager) RepairAll() {
|
func (t *TorrentManager) RepairAll() {
|
||||||
_ = t.repairWorker.Submit(func() {
|
_ = t.repairWorker.Submit(func() {
|
||||||
t.repairAll()
|
t.repairAll()
|
||||||
@@ -53,8 +55,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
expiredLinkTolerance := 24 * time.Hour
|
if torrent.OlderThanDuration(EXPIRED_LINK_TOLERANCE_HOURS * time.Hour) {
|
||||||
if torrent.OlderThanDuration(expiredLinkTolerance) {
|
|
||||||
// first solution: reinsert with same selection
|
// first solution: reinsert with same selection
|
||||||
if t.reinsertTorrent(torrent, "") {
|
if t.reinsertTorrent(torrent, "") {
|
||||||
t.log.Infof("Successfully downloaded torrent %s to repair it", torrent.AccessKey)
|
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")
|
t.log.Warn("Failed to repair by reinserting torrent")
|
||||||
}
|
}
|
||||||
} else {
|
} 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
|
// 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
|
if len(missingFiles) == 1 && torrent.SelectedFiles.Count() == 1 {
|
||||||
// so we need to download 1 extra file to preserve the name
|
t.log.Warnf("Torrent %s is unrepairable, the lone file is expired but still cached in Real-Debrid", torrent.AccessKey)
|
||||||
// this is only relevant if we enable retain_rd_torrent_name
|
return
|
||||||
if len(missingFiles) == 1 && torrent.SelectedFiles.Count() > 1 {
|
} 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
|
// add the first file link encountered with a prefix of http
|
||||||
for _, file := range torrent.SelectedFiles.Items() {
|
for _, file := range torrent.SelectedFiles.Items() {
|
||||||
if strings.HasPrefix(file.Link, "http") {
|
if strings.HasPrefix(file.Link, "http") {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package torrent
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
stdjson "encoding/json"
|
stdjson "encoding/json"
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -128,7 +127,6 @@ func (t *Torrent) ComputeBiggestFileSize() int64 {
|
|||||||
func (t *Torrent) OlderThanDuration(duration time.Duration) bool {
|
func (t *Torrent) OlderThanDuration(duration time.Duration) bool {
|
||||||
latestAdded, err := time.Parse(time.RFC3339, t.LatestAdded)
|
latestAdded, err := time.Parse(time.RFC3339, t.LatestAdded)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error parsing time:", err)
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return time.Since(latestAdded) > duration
|
return time.Since(latestAdded) > duration
|
||||||
|
|||||||
Reference in New Issue
Block a user