fixed Deluge processing for changing category

This commit is contained in:
Flaminel
2025-03-25 22:15:04 +02:00
parent 7b95ec579c
commit 60e838cba7
@@ -217,30 +217,42 @@ public class DelugeService : DownloadService, IDelugeService
.ToList(); .ToList();
} }
public override List<object>? FilterDownloadsToBeCleanedAsync(List<object>? downloads, List<CleanCategory> categories) public override List<object>? FilterDownloadsToBeCleanedAsync(List<object>? downloads, List<CleanCategory> categories) =>
{ downloads
return downloads
?.Cast<TorrentStatus>() ?.Cast<TorrentStatus>()
.Where(x => categories.Any(cat => cat.Name.Equals(x.Label, StringComparison.InvariantCultureIgnoreCase))) .Where(x => categories.Any(cat => cat.Name.Equals(x.Label, StringComparison.InvariantCultureIgnoreCase)))
.Cast<object>() .Cast<object>()
.ToList(); .ToList();
}
public override List<object>? FilterDownloadsToChangeCategoryAsync(List<object>? downloads, List<string> categories) public override List<object>? FilterDownloadsToChangeCategoryAsync(List<object>? downloads, List<string> categories) =>
{ downloads
throw new NotImplementedException(); ?.Cast<TorrentStatus>()
} .Where(x => !string.IsNullOrEmpty(x.Hash))
.Where(x => categories.Any(cat => cat.Equals(x.Label, StringComparison.InvariantCultureIgnoreCase)))
.Cast<object>()
.ToList();
/// <inheritdoc/> /// <inheritdoc/>
public override async Task CleanDownloadsAsync(List<object> downloads, List<CleanCategory> categoriesToClean, HashSet<string> excludedHashes, public override async Task CleanDownloadsAsync(List<object>? downloads, List<CleanCategory> categoriesToClean, HashSet<string> excludedHashes,
IReadOnlyList<string> ignoredDownloads) IReadOnlyList<string> ignoredDownloads)
{ {
if (downloads?.Count is null or 0)
{
return;
}
foreach (TorrentStatus download in downloads) foreach (TorrentStatus download in downloads)
{ {
if (string.IsNullOrEmpty(download.Hash)) if (string.IsNullOrEmpty(download.Hash))
{ {
continue; continue;
} }
if (excludedHashes.Any(x => x.Equals(download.Hash, StringComparison.InvariantCultureIgnoreCase)))
{
_logger.LogDebug("skip | download is used by an arr | {name}", download.Name);
continue;
}
if (ignoredDownloads.Count > 0 && download.ShouldIgnore(ignoredDownloads)) if (ignoredDownloads.Count > 0 && download.ShouldIgnore(ignoredDownloads))
{ {
@@ -255,12 +267,6 @@ public class DelugeService : DownloadService, IDelugeService
{ {
continue; continue;
} }
if (excludedHashes.Any(x => x.Equals(download.Hash, StringComparison.InvariantCultureIgnoreCase)))
{
_logger.LogDebug("skip | download is used by an arr | {name}", download.Name);
continue;
}
if (!_downloadCleanerConfig.DeletePrivate && download.Private) if (!_downloadCleanerConfig.DeletePrivate && download.Private)
{ {
@@ -312,105 +318,77 @@ public class DelugeService : DownloadService, IDelugeService
return; return;
} }
throw new NotImplementedException(); if (!string.IsNullOrEmpty(_downloadCleanerConfig.UnlinkedIgnoredRootDir))
{
_hardLinkFileService.PopulateFileCounts(_downloadCleanerConfig.UnlinkedIgnoredRootDir);
}
foreach (TorrentStatus download in downloads.Cast<TorrentStatus>())
{
if (string.IsNullOrEmpty(download.Hash) || string.IsNullOrEmpty(download.Name) || string.IsNullOrEmpty(download.Label))
{
continue;
}
if (excludedHashes.Any(x => x.Equals(download.Hash, StringComparison.InvariantCultureIgnoreCase)))
{
_logger.LogDebug("skip | download is used by an arr | {name}", download.Name);
continue;
}
// if (_downloadCleanerConfig.NoHardLinksIgnoreRootDir) if (ignoredDownloads.Count > 0 && download.ShouldIgnore(ignoredDownloads))
// { {
// downloads _logger.LogInformation("skip | download is ignored | {name}", download.Name);
// .Cast<TorrentStatus>() continue;
// .Select(x => }
// {
// string? firstDir = GetRootWithFirstDirectory(x.DownloadPath); ContextProvider.Set("downloadName", download.Name);
// ContextProvider.Set("hash", download.Hash);
// if (string.IsNullOrEmpty(firstDir))
// { DelugeContents? contents = null;
// return string.Empty; try
// } {
// contents = await _client.GetTorrentFiles(download.Hash);
// if (firstDir == Path.GetPathRoot(x.DownloadPath)) }
// { catch (Exception exception)
// return string.Empty; {
// } _logger.LogDebug(exception, "failed to find torrent files for {name}", download.Name);
// continue;
// return firstDir; }
// })
// .Where(x => !string.IsNullOrEmpty(x)) bool hasHardlinks = false;
// .Distinct()
// .ToList() ProcessFiles(contents?.Contents, (_, file) =>
// .ForEach(x => {
// { long hardlinkCount = _hardLinkFileService.GetHardLinkCount(file.Path, !string.IsNullOrEmpty(_downloadCleanerConfig.UnlinkedIgnoredRootDir));
// _logger.LogTrace("populating file counts from {dir}", x);
// if (hardlinkCount < 0)
// if (!Directory.Exists(x)) {
// { _logger.LogDebug("skip | could not get file properties | {name}", download.Name);
// throw new ValidationException($"directory \"{x}\" does not exist"); hasHardlinks = true;
// } return;
// }
// _hardLinkFileService.PopulateFileCounts(x);
// }); if (hardlinkCount > 0)
// } {
// hasHardlinks = true;
// foreach (TorrentStatus download in downloads.Cast<TorrentStatus>()) }
// { });
// if (string.IsNullOrEmpty(download.Hash))
// { if (hasHardlinks)
// _logger.LogDebug("skip | download hash is null for {name}", download.Name); {
// continue; _logger.LogDebug("skip | download has hardlinks | {name}", download.Name);
// } continue;
// }
// if (excludedHashes.Any(x => x.Equals(download.Hash, StringComparison.InvariantCultureIgnoreCase)))
// { await _dryRunInterceptor.InterceptAsync(ChangeLabel, download.Hash, _downloadCleanerConfig.UnlinkedTargetCategory);
// _logger.LogDebug("skip | download is used by an arr | {name}", download.Name);
// continue; _logger.LogInformation("category changed for {name}", download.Name);
// }
// await _notifier.NotifyCategoryChanged(download.Label, _downloadCleanerConfig.UnlinkedTargetCategory);
// ContextProvider.Set("downloadName", download.Name);
// ContextProvider.Set("hash", download.Hash); download.Label = _downloadCleanerConfig.UnlinkedTargetCategory;
// }
// DelugeContents? contents = null;
// try
// {
// contents = await _client.GetTorrentFiles(download.Hash);
// }
// catch (Exception exception)
// {
// _logger.LogDebug(exception, "failed to find torrent files for {name}", download.Name);
// continue;
// }
//
// bool hasHardlinks = false;
//
// ProcessFiles(contents?.Contents, (name, file) =>
// {
// string filePath = Path.Combine(download.DownloadPath, file.Path);
//
// long hardlinkCount = _hardLinkFileService.GetHardLinkCount(filePath, _downloadCleanerConfig.NoHardLinksIgnoreRootDir);
//
// if (hardlinkCount < 0)
// {
// _logger.LogDebug("skip | could not get file properties | {name}", download.Name);
// hasHardlinks = true;
// return;
// }
//
// if (hardlinkCount > 0)
// {
// hasHardlinks = true;
// }
// });
//
// if (hasHardlinks)
// {
// _logger.LogDebug("skip | download has hardlinks | {name}", download.Name);
// continue;
// }
//
// await _dryRunInterceptor.InterceptAsync(ChangeLabel, download.Hash, _downloadCleanerConfig.NoHardLinksCategory);
//
// _logger.LogInformation("category changed for {name}", download.Name);
//
// await _notifier.NotifyCategoryChanged(download.Label, _downloadCleanerConfig.NoHardLinksCategory);
// }
} }
/// <inheritdoc/> /// <inheritdoc/>