Fix repairs
This commit is contained in:
@@ -29,7 +29,7 @@ type TorrentManager struct {
|
||||
DownloadMap cmap.ConcurrentMap[string, *realdebrid.Download]
|
||||
Repairs cmap.ConcurrentMap[string, bool]
|
||||
allAccessKeys mapset.Set[string]
|
||||
forRepairs mapset.Set[string]
|
||||
onlyForRepair mapset.Set[string]
|
||||
latestState *LibraryState
|
||||
requiredVersion string
|
||||
workerPool *ants.Pool
|
||||
@@ -44,7 +44,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
|
||||
Config: cfg,
|
||||
Api: api,
|
||||
allAccessKeys: mapset.NewSet[string](),
|
||||
forRepairs: mapset.NewSet[string](),
|
||||
onlyForRepair: mapset.NewSet[string](),
|
||||
latestState: &LibraryState{},
|
||||
requiredVersion: "11.01.2024",
|
||||
workerPool: p,
|
||||
@@ -63,6 +63,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
|
||||
// Fetch downloads
|
||||
t.DownloadCache = cmap.New[*realdebrid.Download]()
|
||||
t.DownloadMap = cmap.New[*realdebrid.Download]()
|
||||
t.Repairs = cmap.New[bool]()
|
||||
if t.Config.EnableDownloadCache() {
|
||||
_ = t.workerPool.Submit(func() {
|
||||
page := 1
|
||||
|
||||
@@ -45,13 +45,13 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
||||
continue
|
||||
}
|
||||
torrentIDs := info.DownloadedIDs.ToSlice()
|
||||
if !info.AnyInProgress() && len(torrentIDs) > 0 && t.forRepairs.Contains(info.DownloadedIDs.ToSlice()[0]) {
|
||||
if !info.AnyInProgress() && len(torrentIDs) > 0 && t.onlyForRepair.Contains(info.DownloadedIDs.ToSlice()[0]) {
|
||||
torrentID := info.DownloadedIDs.ToSlice()[0]
|
||||
// if it's 100% and it's a temp repair, remove it
|
||||
t.Api.DeleteTorrent(torrentID)
|
||||
toReinsert.Add(t.GetKey(info))
|
||||
infoChan <- nil
|
||||
t.forRepairs.Remove(torrentID)
|
||||
t.onlyForRepair.Remove(torrentID)
|
||||
continue
|
||||
}
|
||||
if !info.AnyInProgress() {
|
||||
|
||||
@@ -212,20 +212,6 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
||||
})
|
||||
t.log.Debugf("During repair, zurg found %d broken files for torrent %s", len(brokenFiles), t.GetKey(torrent))
|
||||
|
||||
if len(brokenFiles) == 1 && torrent.SelectedFiles.Count() > 2 {
|
||||
// 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
|
||||
t.log.Debugf("Torrent %s has only 1 broken file, adding 1 extra file to preserve the name", t.GetKey(torrent))
|
||||
for _, file := range torrent.SelectedFiles.Items() {
|
||||
if strings.HasPrefix(file.Link, "http") {
|
||||
brokenFiles = append(brokenFiles, *file)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(brokenFiles) > 0 {
|
||||
t.log.Infof("Redownloading %dof%d files for torrent %s", len(brokenFiles), torrent.SelectedFiles.Count(), t.GetKey(torrent))
|
||||
brokenFileIDs := strings.Join(getFileIDs(brokenFiles), ",")
|
||||
@@ -305,13 +291,13 @@ func (t *TorrentManager) reinsertTorrent(torrent *Torrent, brokenFiles string) b
|
||||
|
||||
if info.Progress != 100 {
|
||||
t.log.Infof("Torrent id=%s is not cached anymore so we have to wait until completion (this should fix the issue already)", info.ID)
|
||||
t.forRepairs.Add(newTorrentID)
|
||||
t.onlyForRepair.Add(newTorrentID)
|
||||
if len(oldTorrentIDs) > 0 {
|
||||
for _, id := range oldTorrentIDs {
|
||||
t.Api.DeleteTorrent(id)
|
||||
}
|
||||
} else {
|
||||
t.forRepairs.Add(newTorrentID)
|
||||
t.onlyForRepair.Add(newTorrentID)
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -324,13 +310,13 @@ func (t *TorrentManager) reinsertTorrent(torrent *Torrent, brokenFiles string) b
|
||||
}
|
||||
|
||||
t.log.Infof("Repair successful id=%s", newTorrentID)
|
||||
t.forRepairs.Add(newTorrentID)
|
||||
t.onlyForRepair.Add(newTorrentID)
|
||||
if len(oldTorrentIDs) > 0 {
|
||||
for _, id := range oldTorrentIDs {
|
||||
t.Api.DeleteTorrent(id)
|
||||
}
|
||||
} else {
|
||||
t.forRepairs.Add(newTorrentID)
|
||||
t.onlyForRepair.Add(newTorrentID)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user