Skip to content

Commit

Permalink
Merge pull request #44 from Terradue/feature/bka-zips-2
Browse files Browse the repository at this point in the history
Fix for NullReferenceException (BKA)
  • Loading branch information
emmanuelmathot authored Feb 14, 2024
2 parents cbaf95e + 849efe5 commit 91ef61b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Stars.Data/Model/Metadata/Bka/BkaMetadataExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected override async Task<StacNode> 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);
Expand All @@ -106,6 +106,11 @@ protected override async Task<StacNode> 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);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 91ef61b

Please sign in to comment.