Log updates

This commit is contained in:
Ben Sarmiento
2024-05-27 15:54:28 +02:00
parent 4ec1c4496d
commit f28255a142
3 changed files with 17 additions and 22 deletions

View File

@@ -13,7 +13,7 @@ const BINS_FILE = "data/bins.json"
// initializeBins reads from bins.json and assigns values to t.trashBin and t.repairBin // initializeBins reads from bins.json and assigns values to t.trashBin and t.repairBin
func (t *TorrentManager) initializeBins() { func (t *TorrentManager) initializeBins() {
if _, err := os.Stat(BINS_FILE); os.IsNotExist(err) { if _, err := os.Stat(BINS_FILE); os.IsNotExist(err) {
t.log.Warn("data/bins.json does not exist. Initializing empty bins.") t.repairLog.Warn("data/bins.json does not exist. Initializing empty bins.")
t.ImmediateBin = mapset.NewSet[string]() t.ImmediateBin = mapset.NewSet[string]()
t.OnceDoneBin = mapset.NewSet[string]() t.OnceDoneBin = mapset.NewSet[string]()
return return
@@ -21,7 +21,7 @@ func (t *TorrentManager) initializeBins() {
fileData, err := os.ReadFile(BINS_FILE) fileData, err := os.ReadFile(BINS_FILE)
if err != nil { if err != nil {
t.log.Errorf("Failed to read bins.json file: %v", err) t.repairLog.Errorf("Failed to read bins.json file: %v", err)
t.ImmediateBin = mapset.NewSet[string]() t.ImmediateBin = mapset.NewSet[string]()
t.OnceDoneBin = mapset.NewSet[string]() t.OnceDoneBin = mapset.NewSet[string]()
return return
@@ -31,15 +31,15 @@ func (t *TorrentManager) initializeBins() {
err = json.Unmarshal(fileData, &data) err = json.Unmarshal(fileData, &data)
if err != nil { if err != nil {
t.log.Errorf("Failed to unmarshal bin data: %v", err) t.repairLog.Errorf("Failed to unmarshal bin data: %v", err)
return return
} }
t.ImmediateBin = mapset.NewSet[string](data["trash_bin"]...) t.ImmediateBin = mapset.NewSet[string](data["trash_bin"]...)
t.OnceDoneBin = mapset.NewSet[string](data["repair_bin"]...) t.OnceDoneBin = mapset.NewSet[string](data["repair_bin"]...)
t.log.Debugf("Bin immediately: %v", t.ImmediateBin.ToSlice()) t.repairLog.Debugf("Bin immediately: %v", t.ImmediateBin.ToSlice())
t.log.Debugf("Bin once done: %v", t.OnceDoneBin.ToSlice()) t.repairLog.Debugf("Bin once done: %v", t.OnceDoneBin.ToSlice())
} }
func (t *TorrentManager) persistBins() { func (t *TorrentManager) persistBins() {
@@ -50,37 +50,37 @@ func (t *TorrentManager) persistBins() {
jsonData, err := json.Marshal(data) jsonData, err := json.Marshal(data)
if err != nil { if err != nil {
t.log.Errorf("Failed to marshal bin data: %v", err) t.repairLog.Errorf("Failed to marshal bin data: %v", err)
return return
} }
file, err := os.Create(BINS_FILE) file, err := os.Create(BINS_FILE)
if err != nil { if err != nil {
t.log.Errorf("Failed to create bins.json file: %v", err) t.repairLog.Errorf("Failed to create bins.json file: %v", err)
return return
} }
defer file.Close() defer file.Close()
_, err = file.Write(jsonData) _, err = file.Write(jsonData)
if err != nil { if err != nil {
t.log.Errorf("Failed to write to bins.json file: %v", err) t.repairLog.Errorf("Failed to write to bins.json file: %v", err)
} }
} }
func (t *TorrentManager) setToBinImmediately(torrentId string) { func (t *TorrentManager) setToBinImmediately(torrentId string) {
t.log.Debugf("id=%s set to delete immediately", torrentId) t.repairLog.Debugf("id=%s set to delete immediately", torrentId)
t.ImmediateBin.Add(torrentId) t.ImmediateBin.Add(torrentId)
t.persistBins() t.persistBins()
} }
func (t *TorrentManager) setToBinOnceDone(torrentId string) { func (t *TorrentManager) setToBinOnceDone(torrentId string) {
t.log.Debugf("id=%s set to delete once it completes", torrentId) t.repairLog.Debugf("id=%s set to delete once it completes", torrentId)
t.OnceDoneBin.Add(torrentId) t.OnceDoneBin.Add(torrentId)
t.persistBins() t.persistBins()
} }
func (t *TorrentManager) setXToBinOnceYDone(deleteId, completeId string) { func (t *TorrentManager) setXToBinOnceYDone(deleteId, completeId string) {
t.log.Debugf("id=%s set to delete once id=%s completes", deleteId, completeId) t.repairLog.Debugf("id=%s set to delete once id=%s completes", deleteId, completeId)
t.OnceDoneBin.Add(fmt.Sprintf("%s-", completeId)) t.OnceDoneBin.Add(fmt.Sprintf("%s-", completeId))
t.OnceDoneBin.Add(fmt.Sprintf("%s-%s", completeId, deleteId)) t.OnceDoneBin.Add(fmt.Sprintf("%s-%s", completeId, deleteId))
t.persistBins() t.persistBins()
@@ -89,7 +89,7 @@ func (t *TorrentManager) setXToBinOnceYDone(deleteId, completeId string) {
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 {
t.log.Errorf("Failed to delete torrent %s: %v", torrentId, err) t.repairLog.Errorf("Failed to delete torrent %s: %v", torrentId, err)
return false return false
} }
t.ImmediateBin.Remove(torrentId) t.ImmediateBin.Remove(torrentId)
@@ -109,7 +109,7 @@ func (t *TorrentManager) binOnceDoneErrorCheck(torrentId, status string) bool {
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.log.Errorf("Failed to delete torrent %s: %v", torrentId, err) t.repairLog.Errorf("Failed to delete torrent %s: %v", torrentId, err)
return false return false
} }
t.OnceDoneBin.Remove(torrentId) t.OnceDoneBin.Remove(torrentId)
@@ -128,7 +128,7 @@ func (t *TorrentManager) binOnceDone(torrentId string) bool {
if strings.Contains(entry, specialCase) { if strings.Contains(entry, specialCase) {
idToDelete := strings.Split(entry, "-")[1] idToDelete := strings.Split(entry, "-")[1]
if err := t.api.DeleteTorrent(idToDelete); err != nil { if err := t.api.DeleteTorrent(idToDelete); err != nil {
t.log.Errorf("Failed to delete torrent %s: %v", idToDelete, err) t.repairLog.Errorf("Failed to delete torrent %s: %v", idToDelete, err)
hasError = true hasError = true
return true return true
} }

View File

@@ -22,9 +22,7 @@ func (t *TorrentManager) CheckDeletedStatus(torrent *Torrent) bool {
func (t *TorrentManager) Delete(accessKey string, deleteInRD bool) { func (t *TorrentManager) Delete(accessKey string, deleteInRD bool) {
allTorrents, _ := t.DirectoryMap.Get(INT_ALL) allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
var hash string
if torrent, ok := allTorrents.Get(accessKey); ok { if torrent, ok := allTorrents.Get(accessKey); ok {
hash = torrent.Hash
if deleteInRD { if deleteInRD {
torrent.DownloadedIDs.Each(func(torrentID string) bool { torrent.DownloadedIDs.Each(func(torrentID string) bool {
t.log.Debugf("Deleting torrent %s (id=%s) in RD", accessKey, torrentID) t.log.Debugf("Deleting torrent %s (id=%s) in RD", accessKey, torrentID)
@@ -40,7 +38,4 @@ func (t *TorrentManager) Delete(accessKey string, deleteInRD bool) {
torrents.Remove(accessKey) torrents.Remove(accessKey)
}) })
allTorrents.Remove(accessKey) allTorrents.Remove(accessKey)
if hash != "" {
t.deleteTorrentFile(hash)
}
} }

View File

@@ -75,6 +75,8 @@ func (t *TorrentManager) refreshTorrents() []string {
wg.Wait() wg.Wait()
close(mergeChan) close(mergeChan)
t.log.Infof("Compiling %d torrents", len(instances))
for torrent := range mergeChan { for torrent := range mergeChan {
if torrent == nil { if torrent == nil {
continue continue
@@ -105,8 +107,6 @@ func (t *TorrentManager) refreshTorrents() []string {
}) })
} }
noInfoCount := 0
// removed torrents // removed torrents
oldPlusNewKeys := mapset.NewSet[string](allTorrents.Keys()...) oldPlusNewKeys := mapset.NewSet[string](allTorrents.Keys()...)
oldPlusNewKeys.Difference(freshAccessKeys).Each(func(accessKey string) bool { oldPlusNewKeys.Difference(freshAccessKeys).Each(func(accessKey string) bool {
@@ -114,7 +114,7 @@ func (t *TorrentManager) refreshTorrents() []string {
return false return false
}) })
t.log.Infof("Compiled into %d torrents, %d were missing info", allTorrents.Count(), noInfoCount) t.log.Infof("Compiled into %d unique torrents", allTorrents.Count())
// 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 {