Adjust file reads and writes

This commit is contained in:
Ben Sarmiento
2024-05-20 22:57:20 +02:00
parent a3a24124a8
commit d5dd9426ed
5 changed files with 22 additions and 34 deletions

View File

@@ -2,6 +2,7 @@ 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) {
@@ -19,8 +20,10 @@ func (t *TorrentManager) CheckDeletedStatus(torrent *Torrent) bool {
func (t *TorrentManager) Delete(accessKey string, deleteInRD bool) {
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
if deleteInRD {
if torrent, ok := allTorrents.Get(accessKey); ok {
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)
@@ -33,4 +36,7 @@ func (t *TorrentManager) Delete(accessKey string, deleteInRD bool) {
torrents.Remove(accessKey)
})
allTorrents.Remove(accessKey)
if hash != "" {
t.deleteTorrentFile(hash)
}
}