Fix upload archive being deleted before disposed

This commit is contained in:
Pat Hartl 2025-02-16 10:48:21 -06:00
parent 54acf8e60c
commit f802448aaa
2 changed files with 10 additions and 5 deletions

View file

@ -15,9 +15,17 @@ public class ImportService<T>(
{
var importArchive = await archiveService.FirstOrDefaultAsync(a => a.ObjectKey == objectKey.ToString());
var importArchivePath = await archiveService.GetArchiveFileLocationAsync(importArchive);
T entity;
using var importZip = ZipFile.OpenRead(importArchivePath);
return await importer.ImportAsync(objectKey, importZip);
using (var importZip = ZipFile.OpenRead(importArchivePath))
{
entity = await importer.ImportAsync(objectKey, importZip);
}
await archiveService.DeleteAsync(importArchive);
return entity;
}
public async Task<T> ImportFromLocalFileAsync(string localFilePath)

View file

@ -23,7 +23,6 @@ public class GameImporter(
public async Task<Game> ImportAsync(Guid objectKey, ZipArchive importZip)
{
var importArchive = await archiveService.FirstOrDefaultAsync(a => a.ObjectKey == objectKey.ToString());
var importArchivePath = await archiveService.GetArchiveFileLocationAsync(importArchive);
var storageLocation = await storageLocationService.GetAsync(importArchive.StorageLocationId);
var manifest = ManifestHelper.Deserialize<GameManifest>(await importZip.ReadAllTextAsync(ManifestHelper.ManifestFilename));
@ -45,8 +44,6 @@ public class GameImporter(
game = await UpdateCollections(game, manifest);
game = await UpdateDependentGames(game, manifest);
await archiveService.DeleteAsync(importArchive, storageLocation);
return game;
}