Skip to content
Merged
Changes from 1 commit
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
27 changes: 13 additions & 14 deletions Vpn.Service/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,27 +453,26 @@ private async Task Start(CancellationToken ct = default)
if (res.Content.Headers.ContentLength >= 0)
TotalBytes = (ulong)res.Content.Headers.ContentLength;

FileStream tempFile;
try
{
tempFile = File.Create(TempDestinationPath, BufferSize,
FileOptions.Asynchronous | FileOptions.SequentialScan);
}
catch (Exception e)
{
_logger.LogError(e, "Failed to create temporary file '{TempDestinationPath}'", TempDestinationPath);
throw;
}

await Download(res, tempFile, ct);
await Download(res, ct);
return;
}

private async Task Download(HttpResponseMessage res, FileStream tempFile, CancellationToken ct)
private async Task Download(HttpResponseMessage res, CancellationToken ct)
{
try
{
var sha1 = res.Headers.Contains("ETag") ? SHA1.Create() : null;
FileStream tempFile;
try
{
tempFile = File.Create(TempDestinationPath, BufferSize,
FileOptions.Asynchronous | FileOptions.SequentialScan);
}
catch (Exception e)
{
_logger.LogError(e, "Failed to create temporary file '{TempDestinationPath}'", TempDestinationPath);
throw;
}
await using (tempFile)
{
var stream = await res.Content.ReadAsStreamAsync(ct);
Expand Down
Loading