Fix issue with bins
This commit is contained in:
@@ -41,6 +41,32 @@ func (t *TorrentManager) initializeBins() {
|
||||
t.log.Debugf("Bin immediately: %v", t.ImmediateBin.ToSlice())
|
||||
t.log.Debugf("Bin once done: %v", t.OnceDoneBin.ToSlice())
|
||||
}
|
||||
|
||||
func (t *TorrentManager) persistBins() {
|
||||
data := map[string]interface{}{
|
||||
"trash_bin": t.ImmediateBin.ToSlice(), // Assuming trashBin is a mapset.Set[string]
|
||||
"repair_bin": t.OnceDoneBin.ToSlice(), // Assuming repairBin is a mapset.Set[string]
|
||||
}
|
||||
|
||||
jsonData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
t.log.Errorf("Failed to marshal bin data: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
file, err := os.Create(BINS_FILE)
|
||||
if err != nil {
|
||||
t.log.Errorf("Failed to create bins.json file: %v", err)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
_, err = file.Write(jsonData)
|
||||
if err != nil {
|
||||
t.log.Errorf("Failed to write to bins.json file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TorrentManager) setToBinImmediately(torrentId string) {
|
||||
t.log.Debugf("Set to delete immediately: %s", torrentId)
|
||||
t.ImmediateBin.Add(torrentId)
|
||||
@@ -99,40 +125,3 @@ func (t *TorrentManager) binOnceDone(torrentId string) bool {
|
||||
|
||||
return found
|
||||
}
|
||||
|
||||
func (t *TorrentManager) persistBins() {
|
||||
data := map[string]interface{}{
|
||||
"trash_bin": t.ImmediateBin.ToSlice(), // Assuming trashBin is a mapset.Set[string]
|
||||
"repair_bin": t.OnceDoneBin.ToSlice(), // Assuming repairBin is a mapset.Set[string]
|
||||
}
|
||||
|
||||
jsonData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
t.log.Errorf("Failed to marshal bin data: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
file, err := os.Create(BINS_FILE)
|
||||
if err != nil {
|
||||
t.log.Errorf("Failed to create bins.json file: %v", err)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
_, err = file.Write(jsonData)
|
||||
if err != nil {
|
||||
t.log.Errorf("Failed to write to bins.json file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TorrentManager) cleanupBins(freshIDs mapset.Set[string]) {
|
||||
t.ImmediateBin.Difference(freshIDs).Each(func(id string) bool {
|
||||
t.ImmediateBin.Remove(id)
|
||||
return false
|
||||
})
|
||||
t.OnceDoneBin.Difference(freshIDs).Each(func(id string) bool {
|
||||
t.OnceDoneBin.Remove(id)
|
||||
return false
|
||||
})
|
||||
t.persistBins()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user