Files
zurg/internal/torrent/delete.go
2024-05-21 01:59:53 +02:00

43 lines
1.3 KiB
Go

package torrent
import cmap "github.com/orcaman/concurrent-map/v2"
// CheckDeletedStatus checks if all files in a torrent are marked as deleted, if so, it returns true
func (t *TorrentManager) CheckDeletedStatus(torrent *Torrent) bool {
var deletedIDs []int
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
if file.State.Is("deleted") {
deletedIDs = append(deletedIDs, file.ID)
}
})
if len(deletedIDs) == torrent.SelectedFiles.Count() && len(deletedIDs) > 0 {
return true
} else if len(deletedIDs) > 0 {
t.writeTorrentToFile(torrent)
}
return false
}
func (t *TorrentManager) Delete(accessKey string, deleteInRD bool) {
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
var hash string
if torrent, ok := allTorrents.Get(accessKey); ok {
hash = torrent.Hash
if deleteInRD {
for torrentID := range torrent.Components {
t.log.Debugf("Deleting torrent %s (id=%s) in RD", accessKey, torrentID)
t.api.DeleteTorrent(torrentID)
t.deleteInfoFile(torrentID)
}
}
}
t.log.Infof("Removing torrent %s from zurg database (not real-debrid)", accessKey)
t.DirectoryMap.IterCb(func(directory string, torrents cmap.ConcurrentMap[string, *Torrent]) {
torrents.Remove(accessKey)
})
allTorrents.Remove(accessKey)
if hash != "" {
t.deleteTorrentFile(hash)
}
}