saveTorrentChangesToDisk when relevant

This commit is contained in:
Ben Sarmiento
2024-01-27 16:32:50 +01:00
parent 582af81ea8
commit b44f2a4b63
6 changed files with 33 additions and 38 deletions

View File

@@ -201,3 +201,18 @@ func (t *TorrentManager) initializeDirectories() {
t.DirectoryMap.Set(directory, cmap.New[*Torrent]())
}
}
func (t *TorrentManager) saveTorrentChangesToDisk(torrent *Torrent, cb func(*Torrent)) {
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
torrent.DownloadedIDs.Union(torrent.InProgressIDs).Each(func(id string) bool {
info, exists := infoCache.Get(id)
if !exists {
return false
}
if cb != nil {
cb(info)
}
t.writeTorrentToFile(id, info)
return false
})
}