Cleanup bins
This commit is contained in:
@@ -86,6 +86,34 @@ func (t *TorrentManager) setXToBinOnceYDone(deleteId, completeId string) {
|
|||||||
t.persistBins()
|
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 {
|
func (t *TorrentManager) binImmediately(torrentId string) bool {
|
||||||
if t.ImmediateBin.Contains(torrentId) {
|
if t.ImmediateBin.Contains(torrentId) {
|
||||||
if err := t.api.DeleteTorrent(torrentId); err != nil {
|
if err := t.api.DeleteTorrent(torrentId); err != nil {
|
||||||
@@ -98,6 +126,7 @@ func (t *TorrentManager) binImmediately(torrentId string) bool {
|
|||||||
return false
|
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 {
|
func (t *TorrentManager) binOnceDoneErrorCheck(torrentId, status string) bool {
|
||||||
if status == "downloading" || status == "downloaded" || status == "uploading" || status == "queued" || status == "compressing" {
|
if status == "downloading" || status == "downloaded" || status == "uploading" || status == "queued" || status == "compressing" {
|
||||||
return false
|
return false
|
||||||
@@ -105,11 +134,14 @@ func (t *TorrentManager) binOnceDoneErrorCheck(torrentId, status string) bool {
|
|||||||
return t.binOnceDone(torrentId)
|
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 {
|
func (t *TorrentManager) binOnceDone(torrentId string) bool {
|
||||||
if t.OnceDoneBin.Contains(torrentId) {
|
if t.OnceDoneBin.Contains(torrentId) {
|
||||||
if err := t.api.DeleteTorrent(torrentId); err != nil {
|
if err := t.api.DeleteTorrent(torrentId); err != nil {
|
||||||
t.repairLog.Warnf("Failed to delete torrent %s: %v", torrentId, err)
|
t.repairLog.Warnf("Failed to delete torrent %s: %v", torrentId, err)
|
||||||
}
|
}
|
||||||
|
t.deleteInfoFile(torrentId)
|
||||||
t.OnceDoneBin.Remove(torrentId)
|
t.OnceDoneBin.Remove(torrentId)
|
||||||
t.persistBins()
|
t.persistBins()
|
||||||
return true
|
return true
|
||||||
@@ -130,6 +162,7 @@ func (t *TorrentManager) binOnceDone(torrentId string) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
t.deleteInfoFile(torrentId)
|
||||||
t.OnceDoneBin.Remove(specialCase)
|
t.OnceDoneBin.Remove(specialCase)
|
||||||
t.persistBins()
|
t.persistBins()
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ func (t *TorrentManager) refreshTorrents() []string {
|
|||||||
freshAccessKeys := mapset.NewSet[string]()
|
freshAccessKeys := mapset.NewSet[string]()
|
||||||
|
|
||||||
for i := range instances {
|
for i := range instances {
|
||||||
|
freshIDs.Add(instances[i].ID)
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
idx := i
|
idx := i
|
||||||
_ = t.workerPool.Submit(func() {
|
_ = t.workerPool.Submit(func() {
|
||||||
@@ -52,8 +53,6 @@ func (t *TorrentManager) refreshTorrents() []string {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
freshIDs.Add(instances[idx].ID)
|
|
||||||
|
|
||||||
tInfo := t.getMoreInfo(instances[idx])
|
tInfo := t.getMoreInfo(instances[idx])
|
||||||
torrent := t.convertToTorrent(tInfo)
|
torrent := t.convertToTorrent(tInfo)
|
||||||
accessKey := t.GetKey(torrent)
|
accessKey := t.GetKey(torrent)
|
||||||
@@ -124,16 +123,23 @@ func (t *TorrentManager) refreshTorrents() []string {
|
|||||||
|
|
||||||
t.log.Infof("Compiled into %d unique torrents", allTorrents.Count())
|
t.log.Infof("Compiled into %d unique torrents", allTorrents.Count())
|
||||||
|
|
||||||
|
t.workerPool.Submit(func() {
|
||||||
// delete info files that are no longer present
|
// delete info files that are no longer present
|
||||||
t.getInfoFiles().Each(func(path string) bool {
|
t.getInfoFiles().Each(func(path string) bool {
|
||||||
path = filepath.Base(path)
|
path = filepath.Base(path)
|
||||||
torrentID := strings.TrimSuffix(path, ".zurginfo")
|
torrentID := strings.TrimSuffix(path, ".zurginfo")
|
||||||
|
// if binOnceDone returns true, it means the info file is deleted
|
||||||
|
// if false, then we check if it's one of the torrents we just fetched
|
||||||
|
// if not, then we delete the info file
|
||||||
if !t.binOnceDone(torrentID) && !freshIDs.Contains(torrentID) {
|
if !t.binOnceDone(torrentID) && !freshIDs.Contains(torrentID) {
|
||||||
t.deleteInfoFile(torrentID)
|
t.deleteInfoFile(torrentID)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.cleanupBins(freshIDs)
|
||||||
|
})
|
||||||
|
|
||||||
return updatedPaths.ToSlice()
|
return updatedPaths.ToSlice()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user