Thanks to visit codestin.com
Credit goes to github.com

Skip to content

File digests not computed when using --base-path #4410

@fernandosci

Description

@fernandosci

What happened:

Syft fails to compute file digests (checksums) for any files. The file digest cataloger processes 0 files instead of the expected count, resulting in missing digests fields in the output.

What you expected to happen:

Files should have digests computed when using --base-path

Steps to reproduce the issue:

  1. Create a test directory and file:
mkdir -p /tmp/syft-bug-test
echo "Hello World" > /tmp/syft-bug-test/test.txt
  1. Create a config file to enable file digests:
cat > /tmp/syft-config.yaml << 'EOF'
file:
  metadata:
    selection: all
    digests:
      - sha256
EOF
  1. Run Syft with --base-path:
syft scan --config /tmp/syft-config.yaml --base-path /tmp /tmp/syft-bug-test -o syft-json
  1. Run Syft without --base-path:
syft scan --config /tmp/syft-config.yaml /tmp/syft-bug-test -o syft-json

Anything else we need to know?:
AI Generated fix (worked for this specific example above)

all_regular_files.go:

func AllRegularFiles(ctx context.Context, resolver file.Resolver) (locations []file.Location) {
	ctx, cancel := context.WithCancel(ctx)
	defer cancel()
	for location := range resolver.AllLocations(ctx) {
		metadata, err := resolver.FileMetadataByLocation(location)
		if err != nil {
			log.Debugf("unable to get metadata for %+v: %+v", location, err)
			continue
		}

		if metadata.Type != stereoscopeFile.TypeRegular {
			continue
		}
		locations = append(locations, location)
	}
	return locations
}
  • Uses locations directly from AllLocations() which already contain valid references
  • Eliminates the redundant FilesByPath() lookup that fails with --base-path
  • Works correctly both with and without --base-path

Environment:

  • Output of syft version: syft 1.38.0-SNAPSHOT-a033ae52
  • OS (e.g: cat /etc/os-release or similar): Ubuntu 22.04.5 LTS

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions