Refactor for hotfix release
This commit is contained in:
41
internal/torrent/delete.go
Normal file
41
internal/torrent/delete.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package torrent
|
||||
|
||||
import cmap "github.com/orcaman/concurrent-map/v2"
|
||||
|
||||
func (t *TorrentManager) CheckDeletedState(torrent *Torrent) bool {
|
||||
var unselectedIDs []int
|
||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||
if file.Link == "unselect" {
|
||||
unselectedIDs = append(unselectedIDs, file.ID)
|
||||
}
|
||||
})
|
||||
if len(unselectedIDs) == torrent.SelectedFiles.Count() && len(unselectedIDs) > 0 {
|
||||
return true
|
||||
} else if len(unselectedIDs) > 0 {
|
||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
||||
t.writeTorrentToFile(id, torrent)
|
||||
return true
|
||||
})
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (t *TorrentManager) Delete(accessKey string, deleteInRD bool) {
|
||||
if deleteInRD {
|
||||
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
|
||||
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
||||
if torrent, ok := allTorrents.Get(accessKey); ok {
|
||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
||||
t.log.Infof("Deleting torrent %s %s in RD", id, accessKey)
|
||||
t.Api.DeleteTorrent(id)
|
||||
infoCache.Remove(id)
|
||||
t.deleteTorrentFile(id)
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
t.log.Infof("Removing torrent %s from zurg database", accessKey)
|
||||
t.DirectoryMap.IterCb(func(directory string, torrents cmap.ConcurrentMap[string, *Torrent]) {
|
||||
torrents.Remove(accessKey)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user