From a5e201c2903c87bcda3ef58c74a5d1d5e3f0a771 Mon Sep 17 00:00:00 2001 From: Justin Hawkins Date: Wed, 15 Mar 2023 05:04:02 +1030 Subject: [PATCH] Restore cleanup --- CHANGELOG.md | 1 + download/download.go | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebc23c8..318ad5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file. - Fixes and improvements to capturing output info and showing it in the UI - Fixes to handling of queued downloads - Fix portable mode to look in binary directory, not current directory +- Automatically cleanup download list, removing old entries automatically ## [v0.5.5] - 2022-04-09 diff --git a/download/download.go b/download/download.go index 9cacd7c..68007fa 100644 --- a/download/download.go +++ b/download/download.go @@ -83,7 +83,7 @@ func (m *Manager) ManageQueue() { m.startQueued(m.MaxPerDomain) m.moveToDest() - // m.cleanup() + m.cleanup() m.Lock.Unlock() time.Sleep(time.Second) @@ -167,16 +167,17 @@ func (m *Manager) startQueued(maxRunning int) { } // cleanup removes old downloads from the list. Hardcoded to remove them one hour -// completion. -func (m *Manager) XXXcleanup() { +// completion. Expects the Manager to be locked. +func (m *Manager) cleanup() { newDLs := []*Download{} for _, dl := range m.Downloads { - + dl.Lock.Lock() if dl.Finished && time.Since(dl.FinishedTS) > time.Duration(time.Hour) { // do nothing } else { newDLs = append(newDLs, dl) } + dl.Lock.Unlock() } m.Downloads = newDLs