From c65c85a0c5fa496dcda170bc3e88db0a559a697a Mon Sep 17 00:00:00 2001 From: Flaminel Date: Sat, 22 Feb 2025 02:27:48 +0200 Subject: [PATCH] fixed categories not being filtered when fetching downloads; fixed inconsistent var naming --- .../DownloadCleaner/DownloadCleanerConfig.cs | 14 +++++++------- .../Verticals/DownloadCleaner/DownloadCleaner.cs | 8 ++++---- .../DownloadClient/QBittorrent/QBitService.cs | 11 +++++++---- code/test/docker-compose.yml | 6 ++++-- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/code/Common/Configuration/DownloadCleaner/DownloadCleanerConfig.cs b/code/Common/Configuration/DownloadCleaner/DownloadCleanerConfig.cs index 149de88..2ebe8ea 100644 --- a/code/Common/Configuration/DownloadCleaner/DownloadCleanerConfig.cs +++ b/code/Common/Configuration/DownloadCleaner/DownloadCleanerConfig.cs @@ -15,13 +15,13 @@ public sealed record DownloadCleanerConfig : IJobConfig public bool DeletePrivate { get; init; } [ConfigurationKeyName("NO_HL_CATEGORY")] - public string NoHardlinksCategory { get; init; } = ""; + public string NoHardLinksCategory { get; init; } = ""; [ConfigurationKeyName("NO_HL_IGNORE_ROOT_DIR")] - public bool IgnoreRootDir { get; init; } + public bool NoHardLinksIgnoreRootDir { get; init; } [ConfigurationKeyName("NO_HL_CATEGORIES")] - public List? HardlinkCategories { get; init; } + public List? NoHardLinksCategories { get; init; } public void Validate() { @@ -42,22 +42,22 @@ public sealed record DownloadCleanerConfig : IJobConfig Categories?.ForEach(x => x.Validate()); - if (string.IsNullOrEmpty(NoHardlinksCategory)) + if (string.IsNullOrEmpty(NoHardLinksCategory)) { return; } - if (HardlinkCategories?.Count is null or 0) + if (NoHardLinksCategories?.Count is null or 0) { throw new ValidationException("no categories configured"); } - if (HardlinkCategories.Contains(NoHardlinksCategory)) + if (NoHardLinksCategories.Contains(NoHardLinksCategory)) { throw new ValidationException("NO_HARDLINKS_CATEGORY is present in the list of filtered categories"); } - if (HardlinkCategories.Any(string.IsNullOrEmpty)) + if (NoHardLinksCategories.Any(string.IsNullOrEmpty)) { throw new ValidationException("empty hardlink filter category found"); } diff --git a/code/Infrastructure/Verticals/DownloadCleaner/DownloadCleaner.cs b/code/Infrastructure/Verticals/DownloadCleaner/DownloadCleaner.cs index 2e0fbaa..e1f85e8 100644 --- a/code/Infrastructure/Verticals/DownloadCleaner/DownloadCleaner.cs +++ b/code/Infrastructure/Verticals/DownloadCleaner/DownloadCleaner.cs @@ -65,18 +65,18 @@ public sealed class DownloadCleaner : GenericHandler List? downloadsToBeCleaned = await _downloadService.GetDownloadsToBeCleanedAsync(_config.Categories); List? downloadsToChangeCategory = null; - if (!string.IsNullOrEmpty(_config.NoHardlinksCategory) && _config.HardlinkCategories?.Count > 0) + if (!string.IsNullOrEmpty(_config.NoHardLinksCategory) && _config.NoHardLinksCategories?.Count > 0) { if (!_hardLinkCategoryCreated) { - _logger.LogTrace("creating category {cat}", _config.NoHardlinksCategory); + _logger.LogTrace("creating category {cat}", _config.NoHardLinksCategory); - await _downloadService.CreateCategoryAsync(_config.NoHardlinksCategory); + await _downloadService.CreateCategoryAsync(_config.NoHardLinksCategory); _hardLinkCategoryCreated = true; } _logger.LogTrace("getting downloads to change category"); - downloadsToChangeCategory = await _downloadService.GetDownloadsToChangeCategoryAsync(_config.HardlinkCategories); + downloadsToChangeCategory = await _downloadService.GetDownloadsToChangeCategoryAsync(_config.NoHardLinksCategories); } bool hasDownloadsToClean = downloadsToBeCleaned?.Count > 0; diff --git a/code/Infrastructure/Verticals/DownloadClient/QBittorrent/QBitService.cs b/code/Infrastructure/Verticals/DownloadClient/QBittorrent/QBitService.cs index 64697e9..0cb0a10 100644 --- a/code/Infrastructure/Verticals/DownloadClient/QBittorrent/QBitService.cs +++ b/code/Infrastructure/Verticals/DownloadClient/QBittorrent/QBitService.cs @@ -226,6 +226,7 @@ public class QBitService : DownloadService, IQBitService Filter = TorrentListFilter.Seeding })) ?.Where(x => !string.IsNullOrEmpty(x.Hash)) + .Where(x => categories.Any(cat => cat.Equals(x.Category, StringComparison.InvariantCultureIgnoreCase))) .Cast() .ToList(); } @@ -313,7 +314,7 @@ public class QBitService : DownloadService, IQBitService public override async Task ChangeCategoryForNoHardLinksAsync(List downloads, HashSet excludedHashes) { - if (_downloadCleanerConfig.IgnoreRootDir) + if (_downloadCleanerConfig.NoHardLinksIgnoreRootDir) { downloads .Cast() @@ -365,6 +366,8 @@ public class QBitService : DownloadService, IQBitService continue; } + ContextProvider.Set("downloadName", download.Name); + ContextProvider.Set("hash", download.Hash); bool hasHardlinks = false; foreach (TorrentContent file in files) @@ -380,7 +383,7 @@ public class QBitService : DownloadService, IQBitService : download.SavePath, file.Name ); - long hardlinkCount = _hardLinkFileService.GetHardLinkCount(filePath, _downloadCleanerConfig.IgnoreRootDir); + long hardlinkCount = _hardLinkFileService.GetHardLinkCount(filePath, _downloadCleanerConfig.NoHardLinksIgnoreRootDir); if (hardlinkCount < 0) { @@ -403,8 +406,8 @@ public class QBitService : DownloadService, IQBitService _logger.LogInformation("changing category for {name}", download.Name); - await ((QBitService)Proxy).ChangeCategory(download.Hash, _downloadCleanerConfig.NoHardlinksCategory); - await _notifier.NotifyCategoryChanged(download.Category, _downloadCleanerConfig.NoHardlinksCategory); + await ((QBitService)Proxy).ChangeCategory(download.Hash, _downloadCleanerConfig.NoHardLinksCategory); + await _notifier.NotifyCategoryChanged(download.Category, _downloadCleanerConfig.NoHardLinksCategory); } } diff --git a/code/test/docker-compose.yml b/code/test/docker-compose.yml index cd6b446..ecb01a8 100644 --- a/code/test/docker-compose.yml +++ b/code/test/docker-compose.yml @@ -215,8 +215,10 @@ services: - DOWNLOADCLEANER__CATEGORIES__1__MIN_SEED_TIME=0 - DOWNLOADCLEANER__CATEGORIES__1__MAX_SEED_TIME=-1 - - DOWNLOADCLEANER__HARDLINK_CATEGORIES__0=tv-sonarr - - DOWNLOADCLEANER__HARDLINK_CATEGORIES__1=radarr + - DOWNLOADCLEANER__NO_HL_CATEGORY=nohardlink + - DOWNLOADCLEANER__NO_HL_IGNORE_ROOT_DIR=true + - DOWNLOADCLEANER__NO_HL_CATEGORIES__0=tv-sonarr + - DOWNLOADCLEANER__NO_HL_CATEGORIES__1=radarr - DOWNLOAD_CLIENT=qbittorrent - QBITTORRENT__URL=http://qbittorrent:8080