Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for NullReferenceException (BKA) #44

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading