Force delete from activedownloads and activeunpacks when a torrent has been deleted.

This commit is contained in:
Roger Far 2024-01-21 22:27:15 -07:00
parent e85366f874
commit 71e1aae5ab
2 changed files with 33 additions and 2 deletions

View file

@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [2.0.60] - 2024-01-21
### Changed
- Fixed bug where downloads could get stuck in active state while deleted.
## [2.0.59] - 2024-01-21 ## [2.0.59] - 2024-01-21
### Changed ### Changed
- Added the simple downloader back and moved the current internal downloader to a new setting. - Added the simple downloader back and moved the current internal downloader to a new setting.

View file

@ -18,14 +18,16 @@ public class TorrentRunner
public static readonly ConcurrentDictionary<Guid, UnpackClient> ActiveUnpackClients = new(); public static readonly ConcurrentDictionary<Guid, UnpackClient> ActiveUnpackClients = new();
private readonly ILogger<TorrentRunner> _logger; private readonly ILogger<TorrentRunner> _logger;
private readonly ILoggerFactory _loggerFactory;
private readonly Torrents _torrents; private readonly Torrents _torrents;
private readonly Downloads _downloads; private readonly Downloads _downloads;
private readonly RemoteService _remoteService; private readonly RemoteService _remoteService;
private readonly HttpClient _httpClient; private readonly HttpClient _httpClient;
public TorrentRunner(ILogger<TorrentRunner> logger, Torrents torrents, Downloads downloads, RemoteService remoteService) public TorrentRunner(ILogger<TorrentRunner> logger, ILoggerFactory loggerFactory, Torrents torrents, Downloads downloads, RemoteService remoteService)
{ {
_logger = logger; _logger = logger;
_loggerFactory = loggerFactory;
_torrents = torrents; _torrents = torrents;
_downloads = downloads; _downloads = downloads;
_remoteService = remoteService; _remoteService = remoteService;
@ -236,6 +238,31 @@ public class TorrentRunner
var torrents = await _torrents.Get(); var torrents = await _torrents.Get();
// Check for deleted torrents that are stuck in the ActiveDownloads or ActiveUnpacks
foreach (var activeDownload in ActiveDownloadClients)
{
var download = torrents.SelectMany(m => m.Downloads).FirstOrDefault(m => m.DownloadId == activeDownload.Key);
if (download == null)
{
await activeDownload.Value.Cancel();
ActiveDownloadClients.TryRemove(activeDownload.Key, out _);
break;
}
}
foreach (var activeUnpacks in ActiveUnpackClients)
{
var download = torrents.SelectMany(m => m.Downloads).FirstOrDefault(m => m.DownloadId == activeUnpacks.Key);
if (download == null)
{
activeUnpacks.Value.Cancel();
ActiveUnpackClients.TryRemove(activeUnpacks.Key, out _);
break;
}
}
// Process torrent retries // Process torrent retries
foreach (var torrent in torrents.Where(m => m.Retry != null)) foreach (var torrent in torrents.Where(m => m.Retry != null))
{ {
@ -357,7 +384,7 @@ public class TorrentRunner
Log($"Setting download path to {downloadPath}", download, torrent); Log($"Setting download path to {downloadPath}", download, torrent);
// Start the download process // Start the download process
var downloadClient = new DownloadClient(download, torrent, downloadPath); var downloadClient = new DownloadClient(_loggerFactory, download, torrent, downloadPath);
Log($"Starting download", download, torrent); Log($"Starting download", download, torrent);