diff --git a/syft/source/all_layers_resolver.go b/syft/source/all_layers_resolver.go index 4293dc825b7..b01d77fab9b 100644 --- a/syft/source/all_layers_resolver.go +++ b/syft/source/all_layers_resolver.go @@ -126,7 +126,7 @@ func (r *allLayersResolver) FilesByGlob(patterns ...string) ([]Location, error) for _, pattern := range patterns { for idx, layerIdx := range r.layers { - results, err := r.img.Layers[layerIdx].Tree.FilesByGlob(pattern, filetree.FollowBasenameLinks, filetree.DoNotFollowDeadBasenameLinks) + results, err := r.img.Layers[layerIdx].SquashedTree.FilesByGlob(pattern, filetree.FollowBasenameLinks, filetree.DoNotFollowDeadBasenameLinks) if err != nil { return nil, fmt.Errorf("failed to resolve files by glob (%s): %w", pattern, err) } diff --git a/test/integration/all_layers_squashed_comparison_test.go b/test/integration/all_layers_squashed_comparison_test.go new file mode 100644 index 00000000000..419fe7071c9 --- /dev/null +++ b/test/integration/all_layers_squashed_comparison_test.go @@ -0,0 +1,20 @@ +package integration + +import ( + "testing" + + "github.com/anchore/syft/syft/source" +) + +func Test_AllLayersIncludesSquashed(t *testing.T) { + // This is a verification test for issue #894 (https://github.com/anchore/syft/issues/894) + allLayers, _ := catalogFixtureImage(t, "image-suse-all-layers", source.AllLayersScope, nil) + squashed, _ := catalogFixtureImage(t, "image-suse-all-layers", source.SquashedScope, nil) + + lenAllLayers := len(allLayers.Artifacts.PackageCatalog.Sorted()) + lenSquashed := len(squashed.Artifacts.PackageCatalog.Sorted()) + + if lenAllLayers < lenSquashed { + t.Errorf("squashed has more packages than all-layers: %d > %d", lenSquashed, lenAllLayers) + } +} diff --git a/test/integration/test-fixtures/image-suse-all-layers/Dockerfile b/test/integration/test-fixtures/image-suse-all-layers/Dockerfile new file mode 100644 index 00000000000..c8d708b5938 --- /dev/null +++ b/test/integration/test-fixtures/image-suse-all-layers/Dockerfile @@ -0,0 +1,2 @@ +FROM registry.suse.com/suse/sle15:15.3.17.20.20 +RUN zypper in -y wget