mirror of
https://github.com/anchore/syft.git
synced 2026-10-30 14:02:26 +01:00
The image source provider now reads images with `image.WithLazyLayerSquashes`: the image squash is built during the read, and each lower layer's squash only when something reads it. A squashed scan never does, so it skips a full file tree copy per layer. - squashed scans: faster, much less memory on images with many layers - `scan`/`attest` with all-layers or deep-squashed stay eager (an internal ctx flag), since eager squashing overlaps with fetching and indexing and is faster when every layer gets read - library callers going through `syft.GetSource` get lazy for every scope, since the scope isn't known when the image is read. All-layers is still correct, just slower - no public API change Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
18 lines
650 B
Go
18 lines
650 B
Go
package internal
|
|
|
|
import "context"
|
|
|
|
type eagerLayerSquashesKey struct{}
|
|
|
|
// WithEagerLayerSquashes has the image source provider build every layer's squashed tree while it reads the
|
|
// image, instead of the first time each one is used. Set it when the scan will read lower layers (any scope but
|
|
// squashed): eager squashing overlaps with fetching and indexing the layers, so those scans finish sooner.
|
|
func WithEagerLayerSquashes(ctx context.Context) context.Context {
|
|
return context.WithValue(ctx, eagerLayerSquashesKey{}, true)
|
|
}
|
|
|
|
func EagerLayerSquashes(ctx context.Context) bool {
|
|
v, _ := ctx.Value(eagerLayerSquashesKey{}).(bool)
|
|
return v
|
|
}
|