Skip to content

Commit

Permalink
fix: Follow symlinks when searching for globs in all-layers scope (#1221
Browse files Browse the repository at this point in the history
)

Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
  • Loading branch information
kzantow authored and spiffcs committed Oct 21, 2022
1 parent e5e272c commit f2545a9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion syft/source/all_layers_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
20 changes: 20 additions & 0 deletions test/integration/all_layers_squashed_comparison_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM registry.suse.com/suse/sle15:15.3.17.20.20
RUN zypper in -y wget

0 comments on commit f2545a9

Please sign in to comment.