Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ui/Logic/Download/YtDlpDownloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ public async Task DownloadYtDlp(IProgress<float>? progress, CancellationToken ca
internal static async Task VerifyChecksumAsync(string filePath, string version, CancellationToken cancellationToken)
{
var assetName = Path.GetFileName(filePath);
if (assetName.EndsWith(".part", StringComparison.Ordinal))
{
assetName = assetName[..^".part".Length];
}

if (!KnownSha256.TryGetValue(version, out var byAsset) ||
!byAsset.TryGetValue(assetName, out var expected))
{
Expand Down
20 changes: 20 additions & 0 deletions tests/UI/Logic/Download/YtDlpDownloadServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,26 @@ await Assert.ThrowsAsync<InvalidOperationException>(() =>
}
}

[Fact]
public async Task VerifyChecksumAsync_PartFile_Mismatch_ThrowsAndDeletesFile()
{
var dir = Path.Combine(Path.GetTempPath(), "VerifyPartMismatch_" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(dir);
var path = Path.Combine(dir, "yt-dlp.exe.part");
await File.WriteAllTextAsync(path, "this is not really yt-dlp", TestContext.Current.CancellationToken);
try
{
await Assert.ThrowsAsync<InvalidOperationException>(() =>
YtDlpDownloadService.VerifyChecksumAsync(path, YtDlpDownloadService.CurrentVersion, TestContext.Current.CancellationToken));

Assert.False(File.Exists(path), "A downloaded .part binary that fails verification must be deleted.");
}
finally
{
Directory.Delete(dir, recursive: true);
}
}

[Fact]
public async Task VerifyChecksumAsync_UnknownAsset_IsNoOp_AndKeepsFile()
{
Expand Down
Loading