Rework repairs again
This commit is contained in:
@@ -29,16 +29,7 @@ func (t *TorrentManager) refreshTorrents() []string {
|
||||
wg.Add(1)
|
||||
_ = t.workerPool.Submit(func() {
|
||||
defer wg.Done()
|
||||
if !t.fixers.Has(instances[idx].ID) {
|
||||
// not a fixer, just regular torrent
|
||||
infoChan <- t.getMoreInfo(instances[idx])
|
||||
return
|
||||
} else if instances[idx].IsDone() {
|
||||
// fixer is done, let's check if it fixed the torrent
|
||||
infoChan <- t.handleFixers(instances[idx])
|
||||
return
|
||||
}
|
||||
infoChan <- nil
|
||||
infoChan <- t.getMoreInfo(instances[idx])
|
||||
})
|
||||
}
|
||||
|
||||
@@ -54,7 +45,7 @@ func (t *TorrentManager) refreshTorrents() []string {
|
||||
continue
|
||||
}
|
||||
accessKey := t.GetKey(info)
|
||||
if !info.AnyInProgress() {
|
||||
if !info.AllInProgress() {
|
||||
newlyFetchedKeys.Add(accessKey)
|
||||
}
|
||||
|
||||
@@ -95,6 +86,10 @@ func (t *TorrentManager) refreshTorrents() []string {
|
||||
return false
|
||||
})
|
||||
|
||||
if t.Config.EnableRepair() {
|
||||
t.handleFixers()
|
||||
}
|
||||
|
||||
return updatedPaths
|
||||
}
|
||||
|
||||
@@ -134,26 +129,26 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
||||
!torrentFromCache.AnyInProgress() &&
|
||||
torrentFromCache.SelectedFiles.Count() == len(rdTorrent.Links) {
|
||||
return torrentFromCache
|
||||
}
|
||||
} else if !exists {
|
||||
torrentFromFile := t.readTorrentFromFile(rdTorrent.ID)
|
||||
if torrentFromFile != nil &&
|
||||
!torrentFromFile.AnyInProgress() &&
|
||||
torrentFromFile.SelectedFiles.Count() == len(rdTorrent.Links) {
|
||||
|
||||
torrentFromFile := t.readTorrentFromFile(rdTorrent.ID)
|
||||
if torrentFromFile != nil &&
|
||||
!torrentFromFile.AnyInProgress() &&
|
||||
torrentFromFile.SelectedFiles.Count() == len(rdTorrent.Links) {
|
||||
hasBrokenFiles := false
|
||||
torrentFromFile.SelectedFiles.IterCb(func(filepath string, file *File) {
|
||||
if file.IsBroken && !file.IsDeleted {
|
||||
hasBrokenFiles = true
|
||||
}
|
||||
})
|
||||
|
||||
hasBrokenFiles := false
|
||||
torrentFromFile.SelectedFiles.IterCb(func(filepath string, file *File) {
|
||||
if file.IsBroken && !file.IsDeleted {
|
||||
hasBrokenFiles = true
|
||||
if !hasBrokenFiles {
|
||||
infoCache.Set(rdTorrent.ID, torrentFromFile)
|
||||
t.ResetSelectedFiles(torrentFromFile)
|
||||
return torrentFromFile
|
||||
} else {
|
||||
t.log.Warnf("Torrent %s has broken files, will not save on info cache", rdTorrent.ID)
|
||||
}
|
||||
})
|
||||
|
||||
if !hasBrokenFiles {
|
||||
infoCache.Set(rdTorrent.ID, torrentFromFile)
|
||||
t.ResetSelectedFiles(torrentFromFile)
|
||||
return torrentFromFile
|
||||
} else {
|
||||
t.log.Warnf("Torrent %s has broken files, will not save on info cache", rdTorrent.ID)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,6 +217,7 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
||||
return &torrent
|
||||
}
|
||||
|
||||
// ResetSelectedFiles will rename the file based on config
|
||||
func (t *TorrentManager) ResetSelectedFiles(torrent *Torrent) {
|
||||
// reset selected files
|
||||
newSelectedFiles := cmap.New[*File]()
|
||||
@@ -258,17 +254,16 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) Torrent {
|
||||
Hash: newer.Hash,
|
||||
Added: newer.Added,
|
||||
|
||||
DownloadedIDs: newer.DownloadedIDs.Union(older.DownloadedIDs),
|
||||
InProgressIDs: newer.InProgressIDs.Union(older.InProgressIDs),
|
||||
UnassignedLinks: newer.UnassignedLinks.Union(older.UnassignedLinks),
|
||||
SelectedFiles: newer.SelectedFiles,
|
||||
DownloadedIDs: newer.DownloadedIDs.Union(older.DownloadedIDs),
|
||||
InProgressIDs: newer.InProgressIDs.Union(older.InProgressIDs),
|
||||
UnassignedLinks: newer.UnassignedLinks.Union(older.UnassignedLinks),
|
||||
SelectedFiles: newer.SelectedFiles,
|
||||
UnrepairableReason: newer.UnrepairableReason,
|
||||
}
|
||||
|
||||
// unrepairable reason
|
||||
if newer.UnrepairableReason != "" && older.UnrepairableReason != "" && newer.UnrepairableReason != older.UnrepairableReason {
|
||||
mainTorrent.UnrepairableReason = fmt.Sprintf("%s, %s", newer.UnrepairableReason, older.UnrepairableReason)
|
||||
} else if newer.UnrepairableReason != "" {
|
||||
mainTorrent.UnrepairableReason = newer.UnrepairableReason
|
||||
if mainTorrent.UnrepairableReason != "" && older.UnrepairableReason != "" && mainTorrent.UnrepairableReason != older.UnrepairableReason {
|
||||
mainTorrent.UnrepairableReason = fmt.Sprintf("%s, %s", mainTorrent.UnrepairableReason, older.UnrepairableReason)
|
||||
} else if older.UnrepairableReason != "" {
|
||||
mainTorrent.UnrepairableReason = older.UnrepairableReason
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user