Cleanup bins

This commit is contained in:
Ben Sarmiento
2024-05-28 01:05:27 +02:00
parent 5e204695df
commit 16e51d50b0
2 changed files with 49 additions and 10 deletions

View File

@@ -38,6 +38,7 @@ func (t *TorrentManager) refreshTorrents() []string {
freshAccessKeys := mapset.NewSet[string]()
for i := range instances {
freshIDs.Add(instances[i].ID)
wg.Add(1)
idx := i
_ = t.workerPool.Submit(func() {
@@ -52,8 +53,6 @@ func (t *TorrentManager) refreshTorrents() []string {
return
}
freshIDs.Add(instances[idx].ID)
tInfo := t.getMoreInfo(instances[idx])
torrent := t.convertToTorrent(tInfo)
accessKey := t.GetKey(torrent)
@@ -124,14 +123,21 @@ func (t *TorrentManager) refreshTorrents() []string {
t.log.Infof("Compiled into %d unique torrents", allTorrents.Count())
// delete info files that are no longer present
t.getInfoFiles().Each(func(path string) bool {
path = filepath.Base(path)
torrentID := strings.TrimSuffix(path, ".zurginfo")
if !t.binOnceDone(torrentID) && !freshIDs.Contains(torrentID) {
t.deleteInfoFile(torrentID)
}
return false
t.workerPool.Submit(func() {
// delete info files that are no longer present
t.getInfoFiles().Each(func(path string) bool {
path = filepath.Base(path)
torrentID := strings.TrimSuffix(path, ".zurginfo")
// if binOnceDone returns true, it means the info file is deleted
// if false, then we check if it's one of the torrents we just fetched
// if not, then we delete the info file
if !t.binOnceDone(torrentID) && !freshIDs.Contains(torrentID) {
t.deleteInfoFile(torrentID)
}
return false
})
t.cleanupBins(freshIDs)
})
return updatedPaths.ToSlice()