Fix rewrites

This commit is contained in:
Ben Sarmiento
2024-05-22 02:26:20 +02:00
parent a9cc689702
commit 9990bf90ca
10 changed files with 149 additions and 114 deletions

View File

@@ -220,15 +220,13 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
// all links are still intact! good!
for i, file := range selectedFiles {
file.Link = info.Links[i]
err := file.State.Event(context.Background(), "repair_file")
if err != nil {
t.log.Warnf("Cannot repair file %s: %v", file.Path, err)
if err := file.State.Event(context.Background(), "repair_file"); err != nil {
t.log.Errorf("Cannot repair file %s: %v", file.Path, err)
}
}
torrent.UnassignedLinks = mapset.NewSet[string]()
err := torrent.State.Event(context.Background(), "repair_torrent")
if err != nil {
t.log.Warnf("Cannot repair torrent %s: %v", torrent.Hash, err)
if err := torrent.State.Event(context.Background(), "mark_as_repaired"); err != nil {
t.log.Errorf("Cannot repair torrent %s: %v", torrent.Hash, err)
}
} else {
torrent.UnassignedLinks = mapset.NewSet[string](info.Links...)
@@ -298,7 +296,6 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) *Torrent {
Added: newer.Added,
Components: mergedComponents,
UnassignedLinks: newer.UnassignedLinks.Union(older.UnassignedLinks),
UnrepairableReason: newer.UnrepairableReason,
State: older.State,
@@ -323,14 +320,29 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) *Torrent {
mainTorrent.SelectedFiles.Set(key, olderFile)
} else if olderFile.State.Is("deleted_file") {
newerFile, _ := mainTorrent.SelectedFiles.Get(key)
err := newerFile.State.Event(context.Background(), "delete_file")
if err != nil {
t.log.Warnf("Cannot delete file %s: %v", key, err)
if err := newerFile.State.Event(context.Background(), "delete_file"); err != nil {
t.log.Errorf("Cannot delete file %s: %v", key, err)
}
}
})
t.CheckDeletedStatus(&mainTorrent)
// unassigned links
mainTorrent.UnassignedLinks = mapset.NewSet[string]()
newer.UnassignedLinks.Union(older.UnassignedLinks).Each(func(link string) bool {
found := false
mainTorrent.SelectedFiles.IterCb(func(key string, file *File) {
if !found && file.Link == link {
found = true
return
}
})
if !found {
mainTorrent.UnassignedLinks.Add(link)
}
return false
})
return &mainTorrent
}