fixed deluge leaving kept private torrents unblocked

This commit is contained in:
Flaminel committed 2026-10-20 15:55:54 +03:00
1 parent 6a7e673806
commit 4a58f5ad21
2 files changed
+40 -2

No files matched your search

@@ -731,6 +731,43 @@ public class DelugeServiceTests : IClassFixture<DelugeServiceFixture>
.ChangeFilesPriority(Arg.Any<string>(), Arg.Any<List<int>>());
}
[Fact]
public async Task AllFilesAreMalware_PrivateTorrentKeptInClient_CallsChangeFilesPriority()
{
const string hash = "all-malware-private-kept-hash";
DelugeService sut = _fixture.CreateSut();
SetMalwareBlockerContext(new ContentBlockerConfig { DeletePrivate = false });
_fixture.ClientWrapper
.GetTorrentStatus(hash)
.Returns(MakeDownloadStatus(hash) with { Private = true });
_fixture.ClientWrapper
.GetTorrentFiles(hash)
.Returns(new DelugeContents
{
Contents = new Dictionary<string, DelugeFileOrDirectory>
{
{ "malware.exe", new DelugeFileOrDirectory { Type = "file", Priority = 1, Index = 0, Path = "malware.exe" } },
},
});
_fixture.FilenameEvaluator
.IsValid(Arg.Any<string>(), Arg.Any<BlocklistType>(), Arg.Any<ConcurrentBag<string>>(), Arg.Any<ConcurrentBag<Regex>>())
.Returns(false);
BlockFilesResult result = await sut.BlockUnwantedFilesAsync(hash, Array.Empty<string>());
result.Found.ShouldBeTrue();
result.IsPrivate.ShouldBeTrue();
result.ShouldRemove.ShouldBeTrue();
result.DeleteReason.ShouldBe(DeleteReason.AllFilesBlocked);
await _fixture.ClientWrapper
.Received(1)
.ChangeFilesPriority(hash, Arg.Is<List<int>>(p => p.Count == 1 && p[0] == 0));
}
[Fact]
public async Task PartialMalware_CallsChangeFilesPriority_AndDoesNotMarkForRemoval()
{
@@ -73,8 +73,9 @@ public partial class DelugeService
await ApplyFileBlockingAsync(result, download.Name, scanItems, malwareBlockerConfig.DeleteIfAnyFileBlocked, async unwantedIndices =>
{
// Zeroing every priority before removal crashes Deluge (#281)
if (result.DeleteReason is DeleteReason.AllFilesBlocked)
// Zeroing every priority before removal crashes Deluge (#281); a kept private torrent still needs it
bool staysInClient = result.IsPrivate && !malwareBlockerConfig.DeletePrivate;
if (result.DeleteReason is DeleteReason.AllFilesBlocked && !staysInClient)
{
return;
}