From 849efe5e12cc43e386ce8529c5a514a32a816f99 Mon Sep 17 00:00:00 2001 From: floeschau Date: Wed, 14 Feb 2024 09:17:52 +0100 Subject: [PATCH] Fix for NullReferenceException --- .../Model/Metadata/Bka/BkaMetadataExtractor.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Stars.Data/Model/Metadata/Bka/BkaMetadataExtractor.cs b/src/Stars.Data/Model/Metadata/Bka/BkaMetadataExtractor.cs index e779c142..9ad23ac0 100644 --- a/src/Stars.Data/Model/Metadata/Bka/BkaMetadataExtractor.cs +++ b/src/Stars.Data/Model/Metadata/Bka/BkaMetadataExtractor.cs @@ -80,7 +80,7 @@ protected override async Task ExtractMetadata(IItem item, string suffi var tmpDestination = LocalFileDestination.Create(_fileSystem.Directory.CreateDirectory(Path.GetDirectoryName(topZipArchiveAsset.Uri.AbsolutePath)), item, true); IAssetsContainer topZipAssets = await topZipArchiveAsset.ExtractToDestinationAsync(tmpDestination, _carrierManager, System.Threading.CancellationToken.None); - IAsset productZipAsset = GetProductZipAsset(topZipAssets); + IAsset productZipAsset = GetProductZipAsset(topZipAsset, topZipAssets); if (productZipAsset != null) { ZipArchiveAsset productZipArchiveAsset = new ZipArchiveAsset(productZipAsset, logger, resourceServiceProvider, _fileSystem); @@ -106,6 +106,11 @@ protected override async Task ExtractMetadata(IItem item, string suffi IAsset[] metadataAssets = GetMetadataAssets(item, innerZipAssetContainers); + if (metadataAssets == null) + { + throw new Exception("No metadata assets found"); + } + BkaMetadata[] metadata = await ReadMetadata(metadataAssets); StacItem stacItem = CreateStacItem(metadata); @@ -544,8 +549,13 @@ protected virtual IAsset GetTopZipAsset(IItem item) return zipAsset; } - protected virtual IAsset GetProductZipAsset(IAssetsContainer container) + protected virtual IAsset GetProductZipAsset(IAsset topAsset, IAssetsContainer container) { + if (topAsset.Uri.AbsolutePath.EndsWith("PRODUCT.zip")) + { + return topAsset; + } + IAsset zipAsset = FindFirstAssetFromFileNameRegex(container, @"PRODUCT\.zip"); return zipAsset; }