Refactor file links and merges

This commit is contained in:
Ben Sarmiento
2024-01-27 17:38:26 +01:00
parent 1913498cbe
commit 1aabcfd322
5 changed files with 59 additions and 104 deletions

View File

@@ -78,7 +78,7 @@ func (t *TorrentManager) repairAll(torrent *Torrent) {
allTorrents, _ = t.DirectoryMap.Get(INT_ALL)
} else {
allTorrents = cmap.New[*Torrent]()
allTorrents.Set(t.GetKey(torrent), torrent)
allTorrents.Set("", torrent)
}
// collect all torrents that need to be repaired
@@ -89,29 +89,6 @@ func (t *TorrentManager) repairAll(torrent *Torrent) {
return
}
// save the broken files to the file cache
// broken files are also added when trying to open a file
if torrent.BrokenLinks.Cardinality() > 0 {
t.saveTorrentChangesToDisk(torrent, func(info *Torrent) {
hasBrokenFiles := false
info.SelectedFiles.IterCb(func(_ string, file *File) {
torrent.BrokenLinks.Each(func(brokenLink string) bool {
if file.Link == brokenLink {
hasBrokenFiles = true
file.Link = ""
return true
}
return false
})
})
if hasBrokenFiles {
info.BrokenLinks = torrent.BrokenLinks
} else {
info.BrokenLinks = mapset.NewSet[string]()
}
})
}
// check 2: for broken files
brokenFileIDs := mapset.NewSet[int]()
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
@@ -204,10 +181,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
file.Link = info.Links[ix]
ix++
})
torrent.BrokenLinks = mapset.NewSet[string]()
t.saveTorrentChangesToDisk(torrent, func(info *Torrent) {
info.BrokenLinks = mapset.NewSet[string]()
})
t.saveTorrentChangesToDisk(torrent, nil)
t.log.Infof("Successfully repaired torrent %s using repair_method#1", t.GetKey(torrent))
return
}
@@ -554,10 +528,7 @@ func (t *TorrentManager) handleFixers(fixer realdebrid.Torrent) *Torrent {
}
}
})
torrent.BrokenLinks = mapset.NewSet[string]()
t.saveTorrentChangesToDisk(torrent, func(info *Torrent) {
info.BrokenLinks = mapset.NewSet[string]()
})
t.saveTorrentChangesToDisk(torrent, nil)
t.log.Infof("Successfully repaired torrent %s using repair_method#2", t.GetKey(torrent))
} else {
t.log.Warnf("repair_method#2: Fixer is done but torrent %s is still broken; let's keep the fixer", t.GetKey(torrent))