delete empty files on failed downloads

This commit is contained in:
rootdarkarchon
2022-12-11 20:42:50 +01:00
parent 189ec03173
commit fc4cee1a3a

View File

@@ -50,6 +50,8 @@ public partial class ApiController
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
var fileName = Path.GetTempFileName(); var fileName = Path.GetTempFileName();
try
{
var fileStream = File.Create(fileName); var fileStream = File.Create(fileName);
await using (fileStream.ConfigureAwait(false)) await using (fileStream.ConfigureAwait(false))
{ {
@@ -69,6 +71,12 @@ public partial class ApiController
return fileName; return fileName;
} }
} }
catch
{
File.Delete(fileName);
throw;
}
}
public int GetDownloadId() => _downloadId++; public int GetDownloadId() => _downloadId++;