From f802448aaaff40dd930b584be56ec4fabb60497e Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Sun, 16 Feb 2025 10:48:21 -0600 Subject: [PATCH] Fix upload archive being deleted before disposed --- LANCommander.Server.Services/ImportService.cs | 12 ++++++++++-- .../Importers/GameImporter.cs | 3 --- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/LANCommander.Server.Services/ImportService.cs b/LANCommander.Server.Services/ImportService.cs index b77312d4..cad8e5a5 100644 --- a/LANCommander.Server.Services/ImportService.cs +++ b/LANCommander.Server.Services/ImportService.cs @@ -15,9 +15,17 @@ public class ImportService( { 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 ImportFromLocalFileAsync(string localFilePath) diff --git a/LANCommander.Server.Services/Importers/GameImporter.cs b/LANCommander.Server.Services/Importers/GameImporter.cs index 79833e90..0d44a00d 100644 --- a/LANCommander.Server.Services/Importers/GameImporter.cs +++ b/LANCommander.Server.Services/Importers/GameImporter.cs @@ -23,7 +23,6 @@ public class GameImporter( public async Task 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(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; }