Fix possible issues

This commit is contained in:
Ben Sarmiento
2024-01-31 18:08:48 +01:00
parent 7794e641ab
commit 4c9b54c01c
6 changed files with 52 additions and 60 deletions

View File

@@ -87,7 +87,9 @@ func (t *TorrentManager) refreshTorrents() []string {
})
if t.Config.EnableRepair() {
t.handleFixers()
t.workerPool.Submit(func() {
t.handleFixers()
})
}
return updatedPaths
@@ -104,11 +106,11 @@ func (t *TorrentManager) StartRefreshJob() {
select {
case <-refreshTicker.C:
checksum := t.getCurrentState()
if t.latestState.equal(checksum) {
if t.latestState.Eq(checksum) {
continue
}
t.SetNewLatestState(checksum)
t.log.Infof("Detected changes! Refreshing %d torrents", checksum.TotalCount)
t.setNewLatestState(checksum)
updatedPaths := t.refreshTorrents()
t.log.Info("Finished refreshing torrents")
@@ -175,15 +177,17 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
continue
}
selectedFiles = append(selectedFiles, &File{
File: file,
Ended: info.Ended,
Link: "", // no link yet
File: file,
Ended: info.Ended,
Link: "", // no link yet
IsBroken: true,
})
}
if len(selectedFiles) == len(info.Links) {
// all links are still intact! good!
for i, file := range selectedFiles {
file.Link = info.Links[i]
file.IsBroken = false
}
torrent.UnassignedLinks = mapset.NewSet[string]()
} else {
@@ -278,7 +282,7 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) Torrent {
// 1. https://*** - the file is available
// 3. empty - the file is not available
mainTorrent.SelectedFiles.IterCb(func(key string, file *File) {
if file.Link == "" {
if file.IsBroken {
file, ok := older.SelectedFiles.Get(key)
if ok {
mainTorrent.SelectedFiles.Set(key, file)