mirror of
https://github.com/anchore/syft.git
synced 2026-10-31 22:46:36 +01:00
Performance improvements around package ID (#698)
* set package ID in catalogers and improve hashing performance Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update setting ID + tests Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
+4
-12
@@ -3,21 +3,19 @@ package source
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mitchellh/hashstructure/v2"
|
||||
|
||||
"github.com/anchore/stereoscope/pkg/file"
|
||||
"github.com/anchore/stereoscope/pkg/image"
|
||||
"github.com/anchore/syft/internal/log"
|
||||
)
|
||||
|
||||
var _ hashstructure.Hashable = (*Location)(nil)
|
||||
|
||||
// Location represents a path relative to a particular filesystem resolved to a specific file.Reference. This struct is used as a key
|
||||
// in content fetching to uniquely identify a file relative to a request (the VirtualPath).
|
||||
type Location struct {
|
||||
Coordinates
|
||||
VirtualPath string // The path to the file which may or may not have hardlinks / symlinks
|
||||
ref file.Reference // The file reference relative to the stereoscope.FileCatalog that has more information about this location.
|
||||
// note: it is IMPORTANT to ignore anything but the coordinates for a Location when considering the ID (hash value)
|
||||
// since the coordinates are the minimally correct ID for a location (symlinks should not come into play)
|
||||
VirtualPath string `hash:"ignore"` // The path to the file which may or may not have hardlinks / symlinks
|
||||
ref file.Reference `hash:"ignore"` // The file reference relative to the stereoscope.FileCatalog that has more information about this location.
|
||||
}
|
||||
|
||||
// NewLocation creates a new Location representing a path without denoting a filesystem or FileCatalog reference.
|
||||
@@ -97,9 +95,3 @@ func (l Location) String() string {
|
||||
}
|
||||
return fmt.Sprintf("Location<%s>", str)
|
||||
}
|
||||
|
||||
func (l Location) Hash() (uint64, error) {
|
||||
// since location is part of the package definition it is important that only coordinates are used during object
|
||||
// hashing. (Location hash should be a pass-through for the coordinates and not include ref or VirtualPath.)
|
||||
return hashstructure.Hash(l.ID(), hashstructure.FormatV2, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user