mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 23:16:30 +01:00
rename file.Location.VirtualPath to AccessPath (#2288)
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
@@ -63,7 +63,7 @@ func (i *Cataloger) catalogLocation(resolver file.Resolver, location file.Locati
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer internal.CloseAndLogError(contentReader, location.VirtualPath)
|
||||
defer internal.CloseAndLogError(contentReader, location.AccessPath)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
encoder := base64.NewEncoder(base64.StdEncoding, buf)
|
||||
|
||||
@@ -81,7 +81,7 @@ func (i *Cataloger) catalogLocation(resolver file.Resolver, location file.Locati
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer internal.CloseAndLogError(contentReader, location.VirtualPath)
|
||||
defer internal.CloseAndLogError(contentReader, location.AccessPath)
|
||||
|
||||
digests, err := intFile.NewDigestsFromFile(contentReader, i.hashes)
|
||||
if err != nil {
|
||||
|
||||
@@ -15,10 +15,10 @@ import (
|
||||
|
||||
func Test_allRegularFiles(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
setup func() file.Resolver
|
||||
wantRealPaths *strset.Set
|
||||
wantVirtualPaths *strset.Set
|
||||
name string
|
||||
setup func() file.Resolver
|
||||
wantRealPaths *strset.Set
|
||||
wantAccessPaths *strset.Set
|
||||
}{
|
||||
{
|
||||
name: "image",
|
||||
@@ -35,8 +35,8 @@ func Test_allRegularFiles(t *testing.T) {
|
||||
|
||||
return r
|
||||
},
|
||||
wantRealPaths: strset.New("/file-1.txt"),
|
||||
wantVirtualPaths: strset.New("/file-1.txt", "/symlink-1", "/hardlink-1"),
|
||||
wantRealPaths: strset.New("/file-1.txt"),
|
||||
wantAccessPaths: strset.New("/file-1.txt", "/symlink-1", "/hardlink-1"),
|
||||
},
|
||||
{
|
||||
name: "directory",
|
||||
@@ -47,8 +47,8 @@ func Test_allRegularFiles(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
return r
|
||||
},
|
||||
wantRealPaths: strset.New("file1.txt", "nested/file2.txt"),
|
||||
wantVirtualPaths: strset.New("file1.txt", "nested/file2.txt", "nested/linked-file1.txt"),
|
||||
wantRealPaths: strset.New("file1.txt", "nested/file2.txt"),
|
||||
wantAccessPaths: strset.New("file1.txt", "nested/file2.txt", "nested/linked-file1.txt"),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@@ -59,8 +59,8 @@ func Test_allRegularFiles(t *testing.T) {
|
||||
virtualLocations := strset.New()
|
||||
for _, l := range locations {
|
||||
realLocations.Add(l.RealPath)
|
||||
if l.VirtualPath != "" {
|
||||
virtualLocations.Add(l.VirtualPath)
|
||||
if l.AccessPath != "" {
|
||||
virtualLocations.Add(l.AccessPath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,10 +68,10 @@ func Test_allRegularFiles(t *testing.T) {
|
||||
realLocations.Remove("/hardlink-1")
|
||||
virtualLocations.Remove("/hardlink-1")
|
||||
tt.wantRealPaths.Remove("/hardlink-1")
|
||||
tt.wantVirtualPaths.Remove("/hardlink-1")
|
||||
tt.wantAccessPaths.Remove("/hardlink-1")
|
||||
|
||||
assert.ElementsMatch(t, tt.wantRealPaths.List(), realLocations.List(), "real paths differ: "+cmp.Diff(tt.wantRealPaths.List(), realLocations.List()))
|
||||
assert.ElementsMatch(t, tt.wantVirtualPaths.List(), virtualLocations.List(), "virtual paths differ: "+cmp.Diff(tt.wantVirtualPaths.List(), virtualLocations.List()))
|
||||
assert.ElementsMatch(t, tt.wantAccessPaths.List(), virtualLocations.List(), "virtual paths differ: "+cmp.Diff(tt.wantAccessPaths.List(), virtualLocations.List()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ func extractValue(resolver file.Resolver, location file.Location, start, length
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to fetch reader for location=%q : %w", location, err)
|
||||
}
|
||||
defer internal.CloseAndLogError(readCloser, location.VirtualPath)
|
||||
defer internal.CloseAndLogError(readCloser, location.AccessPath)
|
||||
|
||||
n, err := io.CopyN(io.Discard, readCloser, start)
|
||||
if err != nil {
|
||||
|
||||
@@ -16,7 +16,7 @@ func catalogLocationByLine(resolver file.Resolver, location file.Location, patte
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to fetch reader for location=%q : %w", location, err)
|
||||
}
|
||||
defer internal.CloseAndLogError(readCloser, location.VirtualPath)
|
||||
defer internal.CloseAndLogError(readCloser, location.AccessPath)
|
||||
|
||||
var scanner = bufio.NewReader(readCloser)
|
||||
var position int64
|
||||
@@ -65,7 +65,7 @@ func searchForSecretsWithinLine(resolver file.Resolver, location file.Location,
|
||||
if secret != nil {
|
||||
secrets = append(secrets, *secret)
|
||||
}
|
||||
internal.CloseAndLogError(reader, location.VirtualPath)
|
||||
internal.CloseAndLogError(reader, location.AccessPath)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
-23
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
// 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).
|
||||
// in content fetching to uniquely identify a file relative to a request (the AccessPath).
|
||||
type Location struct {
|
||||
LocationData `cyclonedx:""`
|
||||
LocationMetadata `cyclonedx:""`
|
||||
@@ -20,8 +20,8 @@ type LocationData struct {
|
||||
Coordinates `cyclonedx:""` // Empty string here means there is no intermediate property name, e.g. syft:locations:0:path without "coordinates"
|
||||
// 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" json:"accessPath"` // 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.
|
||||
AccessPath string `hash:"ignore" json:"accessPath"` // 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.
|
||||
}
|
||||
|
||||
func (l LocationData) Reference() file.Reference {
|
||||
@@ -68,7 +68,7 @@ func NewLocation(realPath string) Location {
|
||||
Coordinates: Coordinates{
|
||||
RealPath: realPath,
|
||||
},
|
||||
VirtualPath: realPath,
|
||||
AccessPath: realPath,
|
||||
},
|
||||
LocationMetadata: LocationMetadata{
|
||||
Annotations: map[string]string{},
|
||||
@@ -77,13 +77,13 @@ func NewLocation(realPath string) Location {
|
||||
}
|
||||
|
||||
// NewVirtualLocation creates a new location for a path accessed by a virtual path (a path with a symlink or hardlink somewhere in the path)
|
||||
func NewVirtualLocation(realPath, virtualPath string) Location {
|
||||
func NewVirtualLocation(realPath, accessPath string) Location {
|
||||
return Location{
|
||||
LocationData: LocationData{
|
||||
Coordinates: Coordinates{
|
||||
RealPath: realPath,
|
||||
},
|
||||
VirtualPath: virtualPath,
|
||||
AccessPath: accessPath,
|
||||
},
|
||||
LocationMetadata: LocationMetadata{
|
||||
Annotations: map[string]string{},
|
||||
@@ -95,7 +95,7 @@ func NewLocationFromCoordinates(coordinates Coordinates) Location {
|
||||
return Location{
|
||||
LocationData: LocationData{
|
||||
Coordinates: coordinates,
|
||||
VirtualPath: coordinates.RealPath,
|
||||
AccessPath: coordinates.RealPath,
|
||||
},
|
||||
LocationMetadata: LocationMetadata{
|
||||
Annotations: map[string]string{},
|
||||
@@ -103,11 +103,11 @@ func NewLocationFromCoordinates(coordinates Coordinates) Location {
|
||||
}
|
||||
|
||||
// NewVirtualLocationFromCoordinates creates a new location for the given Coordinates via a virtual path.
|
||||
func NewVirtualLocationFromCoordinates(coordinates Coordinates, virtualPath string) Location {
|
||||
func NewVirtualLocationFromCoordinates(coordinates Coordinates, accessPath string) Location {
|
||||
return Location{
|
||||
LocationData: LocationData{
|
||||
Coordinates: coordinates,
|
||||
VirtualPath: virtualPath,
|
||||
AccessPath: accessPath,
|
||||
},
|
||||
LocationMetadata: LocationMetadata{
|
||||
Annotations: map[string]string{},
|
||||
@@ -115,7 +115,7 @@ func NewVirtualLocationFromCoordinates(coordinates Coordinates, virtualPath stri
|
||||
}
|
||||
|
||||
// NewLocationFromImage creates a new Location representing the given path (extracted from the Reference) relative to the given image.
|
||||
func NewLocationFromImage(virtualPath string, ref file.Reference, img *image.Image) Location {
|
||||
func NewLocationFromImage(accessPath string, ref file.Reference, img *image.Image) Location {
|
||||
layer := img.FileCatalog.Layer(ref)
|
||||
return Location{
|
||||
LocationData: LocationData{
|
||||
@@ -123,8 +123,8 @@ func NewLocationFromImage(virtualPath string, ref file.Reference, img *image.Ima
|
||||
RealPath: string(ref.RealPath),
|
||||
FileSystemID: layer.Metadata.Digest,
|
||||
},
|
||||
VirtualPath: virtualPath,
|
||||
ref: ref,
|
||||
AccessPath: accessPath,
|
||||
ref: ref,
|
||||
},
|
||||
LocationMetadata: LocationMetadata{
|
||||
Annotations: map[string]string{},
|
||||
@@ -139,8 +139,8 @@ func NewLocationFromDirectory(responsePath string, ref file.Reference) Location
|
||||
Coordinates: Coordinates{
|
||||
RealPath: responsePath,
|
||||
},
|
||||
VirtualPath: responsePath,
|
||||
ref: ref,
|
||||
AccessPath: responsePath,
|
||||
ref: ref,
|
||||
},
|
||||
LocationMetadata: LocationMetadata{
|
||||
Annotations: map[string]string{},
|
||||
@@ -149,14 +149,14 @@ func NewLocationFromDirectory(responsePath string, ref file.Reference) Location
|
||||
}
|
||||
|
||||
// NewVirtualLocationFromDirectory creates a new Location representing the given path (extracted from the Reference) relative to the given directory with a separate virtual access path.
|
||||
func NewVirtualLocationFromDirectory(responsePath, virtualResponsePath string, ref file.Reference) Location {
|
||||
func NewVirtualLocationFromDirectory(responsePath, responseAccessPath string, ref file.Reference) Location {
|
||||
return Location{
|
||||
LocationData: LocationData{
|
||||
Coordinates: Coordinates{
|
||||
RealPath: responsePath,
|
||||
},
|
||||
VirtualPath: virtualResponsePath,
|
||||
ref: ref,
|
||||
AccessPath: responseAccessPath,
|
||||
ref: ref,
|
||||
},
|
||||
LocationMetadata: LocationMetadata{
|
||||
Annotations: map[string]string{},
|
||||
@@ -164,9 +164,9 @@ func NewVirtualLocationFromDirectory(responsePath, virtualResponsePath string, r
|
||||
}
|
||||
}
|
||||
|
||||
func (l Location) AccessPath() string {
|
||||
if l.VirtualPath != "" {
|
||||
return l.VirtualPath
|
||||
func (l Location) Path() string {
|
||||
if l.AccessPath != "" {
|
||||
return l.AccessPath
|
||||
}
|
||||
return l.RealPath
|
||||
}
|
||||
@@ -179,8 +179,8 @@ func (l Location) String() string {
|
||||
|
||||
str += fmt.Sprintf("RealPath=%q", l.RealPath)
|
||||
|
||||
if l.VirtualPath != "" && l.VirtualPath != l.RealPath {
|
||||
str += fmt.Sprintf(" VirtualPath=%q", l.VirtualPath)
|
||||
if l.AccessPath != "" && l.AccessPath != l.RealPath {
|
||||
str += fmt.Sprintf(" AccessPath=%q", l.AccessPath)
|
||||
}
|
||||
|
||||
if l.FileSystemID != "" {
|
||||
@@ -191,6 +191,6 @@ func (l Location) String() string {
|
||||
|
||||
func (l Location) Equals(other Location) bool {
|
||||
return l.RealPath == other.RealPath &&
|
||||
l.VirtualPath == other.VirtualPath &&
|
||||
l.AccessPath == other.AccessPath &&
|
||||
l.FileSystemID == other.FileSystemID
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ func TestLocationSet(t *testing.T) {
|
||||
RealPath: "/etc/hosts",
|
||||
FileSystemID: "a",
|
||||
},
|
||||
VirtualPath: "/var/etc/hosts",
|
||||
AccessPath: "/var/etc/hosts",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ func TestLocationSet(t *testing.T) {
|
||||
RealPath: "/etc/hosts",
|
||||
FileSystemID: "a",
|
||||
},
|
||||
VirtualPath: "/home/wagoodman/hosts",
|
||||
AccessPath: "/home/wagoodman/hosts",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ func TestLocationSet(t *testing.T) {
|
||||
RealPath: "/bin",
|
||||
FileSystemID: "a",
|
||||
},
|
||||
VirtualPath: "/usr/bin",
|
||||
AccessPath: "/usr/bin",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ func TestLocationSet(t *testing.T) {
|
||||
RealPath: "/bin",
|
||||
FileSystemID: "b",
|
||||
},
|
||||
VirtualPath: "/usr/bin",
|
||||
AccessPath: "/usr/bin",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ func TestLocationSet_Hash(t *testing.T) {
|
||||
RealPath: "/etc/hosts",
|
||||
FileSystemID: "a",
|
||||
},
|
||||
VirtualPath: "/var/etc/hosts",
|
||||
AccessPath: "/var/etc/hosts",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ func TestLocationSet_Hash(t *testing.T) {
|
||||
RealPath: "/bin",
|
||||
FileSystemID: "a",
|
||||
},
|
||||
VirtualPath: "/usr/bin",
|
||||
AccessPath: "/usr/bin",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ func TestLocationSet_Hash(t *testing.T) {
|
||||
RealPath: "/bin",
|
||||
FileSystemID: "b",
|
||||
},
|
||||
VirtualPath: "/usr/bin",
|
||||
AccessPath: "/usr/bin",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ func TestLocation_ID(t *testing.T) {
|
||||
l := Location{
|
||||
LocationData: LocationData{
|
||||
Coordinates: test.coordinates,
|
||||
VirtualPath: test.virtualPath,
|
||||
AccessPath: test.virtualPath,
|
||||
ref: test.ref,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@ func (l Locations) Len() int {
|
||||
|
||||
func (l Locations) Less(i, j int) bool {
|
||||
if l[i].RealPath == l[j].RealPath {
|
||||
if l[i].VirtualPath == l[j].VirtualPath {
|
||||
if l[i].AccessPath == l[j].AccessPath {
|
||||
return l[i].FileSystemID < l[j].FileSystemID
|
||||
}
|
||||
return l[i].VirtualPath < l[j].VirtualPath
|
||||
return l[i].AccessPath < l[j].AccessPath
|
||||
}
|
||||
return l[i].RealPath < l[j].RealPath
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user