fix: unknowns, better full vs local path handling

Signed-off-by: Keith Zantow <kzantow@gmail.com>
This commit is contained in:
Keith Zantow
2026-10-20 11:15:17 -04:00
parent 3cdf97ebad
commit a1f7c52d89
25 changed files with 619 additions and 225 deletions
+4 -16
View File
@@ -4,7 +4,6 @@ import (
"context"
"crypto"
"github.com/anchore/syft/internal/archive"
"github.com/anchore/syft/internal/sbomsync"
"github.com/anchore/syft/syft/artifact"
"github.com/anchore/syft/syft/cataloging/filecataloging"
@@ -40,7 +39,7 @@ func newFileDigestCatalogerTask(selection file.Selection, hashers []crypto.Hash,
accessor := builder.(sbomsync.Accessor)
coordinates, ok := coordinatesForSelection(ctx, selection, builder.(sbomsync.Accessor))
coordinates, ok := coordinatesForSelection(selection, builder.(sbomsync.Accessor))
if !ok {
return nil
}
@@ -71,7 +70,7 @@ func newFileMetadataCatalogerTask(selection file.Selection, tags ...string) Task
accessor := builder.(sbomsync.Accessor)
coordinates, ok := coordinatesForSelection(ctx, selection, builder.(sbomsync.Accessor))
coordinates, ok := coordinatesForSelection(selection, builder.(sbomsync.Accessor))
if !ok {
return nil
}
@@ -142,12 +141,7 @@ func newExecutableCatalogerTask(selection file.Selection, cfg executable.Config,
// TODO: this should be replaced with a fix that allows passing a coordinate or location iterator to the cataloger
// Today internal to both cataloger this functions differently: a slice of coordinates vs a channel of locations
//
// Only coordinates in the resolver's own frame are returned: inside an archive, the files of that archive,
// and at the scan root, files outside any archive. A package's location can be in another frame (a nested
// java package is located at the archive in its parent), and looking that path up here would miss or,
// worse, hit an unrelated file of the same name.
func coordinatesForSelection(ctx context.Context, selection file.Selection, accessor sbomsync.Accessor) ([]file.Coordinates, bool) {
func coordinatesForSelection(selection file.Selection, accessor sbomsync.Accessor) ([]file.Coordinates, bool) {
if selection == file.AllFilesSelection {
return nil, true
}
@@ -175,13 +169,7 @@ func coordinatesForSelection(ctx context.Context, selection file.Selection, acce
}
})
frame := archive.TraversalFromContext(ctx).FullTraversalArchivePath()
var coords []file.Coordinates
for _, c := range coordinates.ToSlice() {
if archive.ContainerPath(c) == frame {
coords = append(coords, c)
}
}
coords := coordinates.ToSlice()
if len(coords) == 0 {
return nil, false