makes autoclient delete old data files

This commit is contained in:
Ben 2024-10-21 11:10:39 +02:00
parent 9e842207ab
commit d452293cac
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
1 changed files with 21 additions and 2 deletions

View File

@ -84,8 +84,15 @@ namespace AutoClient
private async Task<string> StartNewPurchase()
{
var file = await CreateFile();
var cid = await UploadFile(file);
return await RequestStorage(cid);
try
{
var cid = await UploadFile(file);
return await RequestStorage(cid);
}
finally
{
DeleteFile(file);
}
}
private async Task<string> CreateFile()
@ -93,6 +100,18 @@ namespace AutoClient
return await app.Generator.Generate();
}
private void DeleteFile(string file)
{
try
{
File.Delete(file);
}
catch (Exception exc)
{
app.Log.Error($"Failed to delete file '{file}': {exc}");
}
}
private async Task<ContentId> UploadFile(string filename)
{
using var fileStream = File.OpenRead(filename);