Bin error checks

This commit is contained in:
Ben Sarmiento
2024-05-27 06:25:55 +02:00
parent fb37fd69e1
commit ac89f53896
4 changed files with 55 additions and 81 deletions

View File

@@ -1,6 +1,7 @@
package torrent
import (
"fmt"
"os"
"strings"
@@ -64,30 +65,35 @@ func (t *TorrentManager) binImmediately(torrentId string) bool {
return false
}
func (t *TorrentManager) binOnceDone(torrentId string) bool {
if t.OnceDoneBin.Contains(torrentId) {
if err := t.api.DeleteTorrent(torrentId); err != nil {
t.log.Errorf("Failed to delete torrent %s: %v", torrentId, err)
return false
}
t.OnceDoneBin.Remove(torrentId)
return true
func (t *TorrentManager) binOnceDoneErrorCheck(torrentId, status string) bool {
okStatuses := mapset.NewSet("downloading", "downloaded", "uploading", "queued", "compressing")
if !okStatuses.Contains(status) {
return t.binOnceDone(torrentId)
}
return false
}
// special case: xxx-yyy means if xxx is done, delete yyy
func (t *TorrentManager) binOnceDone(torrentId string) bool {
found := false
specialCases := t.OnceDoneBin.ToSlice()
for _, specialCase := range specialCases {
if strings.Contains(specialCase, "-") {
parts := strings.Split(specialCase, "-")
if parts[0] == torrentId {
if err := t.api.DeleteTorrent(parts[1]); err != nil {
t.log.Errorf("Failed to delete torrent %s: %v", parts[1], err)
continue
}
t.OnceDoneBin.Remove(specialCase)
found = true
binnedIDs := t.OnceDoneBin.ToSlice()
// special case: xxx-yyy means if xxx is done, delete yyy
specialCase := fmt.Sprintf("%s-", torrentId)
for _, entry := range binnedIDs {
if strings.Contains(entry, specialCase) {
idToDelete := strings.Split(entry, "-")[1]
if err := t.api.DeleteTorrent(idToDelete); err != nil {
t.log.Errorf("Failed to delete torrent %s: %v", idToDelete, err)
continue
}
t.OnceDoneBin.Remove(entry)
found = true
} else if entry == torrentId {
if err := t.api.DeleteTorrent(torrentId); err != nil {
t.log.Errorf("Failed to delete torrent %s: %v", torrentId, err)
return false
}
t.OnceDoneBin.Remove(torrentId)
return true
}
}