Cleanup bins
This commit is contained in:
@@ -86,6 +86,34 @@ func (t *TorrentManager) setXToBinOnceYDone(deleteId, completeId string) {
|
||||
t.persistBins()
|
||||
}
|
||||
|
||||
func (t *TorrentManager) cleanupBins(freshIDs mapset.Set[string]) {
|
||||
t.ImmediateBin.Clone().Each(func(entry string) bool {
|
||||
if !freshIDs.Contains(entry) {
|
||||
t.ImmediateBin.Remove(entry)
|
||||
}
|
||||
return false
|
||||
})
|
||||
t.OnceDoneBin.Clone().Each(func(entry string) bool {
|
||||
// check if the entry is a special case
|
||||
if strings.Contains(entry, "-") {
|
||||
// format is: id1-id2 or id1-
|
||||
// if either id1 or id2 is not fresh, remove the entry
|
||||
ids := strings.Split(entry, "-")
|
||||
if !freshIDs.Contains(ids[0]) || (ids[1] != "" && !freshIDs.Contains(ids[1])) {
|
||||
t.OnceDoneBin.Remove(entry)
|
||||
}
|
||||
return false
|
||||
}
|
||||
if !freshIDs.Contains(entry) {
|
||||
t.OnceDoneBin.Remove(entry)
|
||||
}
|
||||
return false
|
||||
})
|
||||
t.persistBins()
|
||||
}
|
||||
|
||||
// binImmediatelyErrorCheck checks if the torrent is in the ImmediateBin and deletes it if it is.
|
||||
// returns true if the torrent was in the bin and was deleted, false otherwise
|
||||
func (t *TorrentManager) binImmediately(torrentId string) bool {
|
||||
if t.ImmediateBin.Contains(torrentId) {
|
||||
if err := t.api.DeleteTorrent(torrentId); err != nil {
|
||||
@@ -98,6 +126,7 @@ func (t *TorrentManager) binImmediately(torrentId string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// binOnceDoneErrorCheck checks if the torrent is in error states and then checks if it should be deleted
|
||||
func (t *TorrentManager) binOnceDoneErrorCheck(torrentId, status string) bool {
|
||||
if status == "downloading" || status == "downloaded" || status == "uploading" || status == "queued" || status == "compressing" {
|
||||
return false
|
||||
@@ -105,11 +134,14 @@ func (t *TorrentManager) binOnceDoneErrorCheck(torrentId, status string) bool {
|
||||
return t.binOnceDone(torrentId)
|
||||
}
|
||||
|
||||
// binOnceDone checks if the torrent is in the OnceDoneBin and deletes it if it is.
|
||||
// returns true if the torrent was in the bin and was deleted, false otherwise
|
||||
func (t *TorrentManager) binOnceDone(torrentId string) bool {
|
||||
if t.OnceDoneBin.Contains(torrentId) {
|
||||
if err := t.api.DeleteTorrent(torrentId); err != nil {
|
||||
t.repairLog.Warnf("Failed to delete torrent %s: %v", torrentId, err)
|
||||
}
|
||||
t.deleteInfoFile(torrentId)
|
||||
t.OnceDoneBin.Remove(torrentId)
|
||||
t.persistBins()
|
||||
return true
|
||||
@@ -130,6 +162,7 @@ func (t *TorrentManager) binOnceDone(torrentId string) bool {
|
||||
}
|
||||
return false
|
||||
})
|
||||
t.deleteInfoFile(torrentId)
|
||||
t.OnceDoneBin.Remove(specialCase)
|
||||
t.persistBins()
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user