rename location.VirtualPath to AccessPath

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman 2022-03-22 18:24:50 -04:00
parent f999604a29
commit a3dc0fa97d
No known key found for this signature in database
GPG Key ID: 5CB45AE22BAB7EA7
24 changed files with 84 additions and 84 deletions

View File

@ -191,7 +191,7 @@ func toSyftCoordinates(f *spdx.File2_2) file.Coordinates {
func toSyftLocation(f *spdx.File2_2) *file.Location { func toSyftLocation(f *spdx.File2_2) *file.Location {
return &file.Location{ return &file.Location{
Coordinates: toSyftCoordinates(f), Coordinates: toSyftCoordinates(f),
VirtualPath: f.FileName, AccessPath: f.FileName,
} }
} }

View File

@ -80,7 +80,7 @@ func (c Classifier) Classify(resolver source.FileResolver, location file.Locatio
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer internal.CloseAndLogError(contentReader, location.VirtualPath) defer internal.CloseAndLogError(contentReader, location.AccessPath)
// TODO: there is room for improvement here, as this may use an excessive amount of memory. Alternate approach is to leverage a RuneReader. // TODO: there is room for improvement here, as this may use an excessive amount of memory. Alternate approach is to leverage a RuneReader.
contents, err := ioutil.ReadAll(contentReader) contents, err := ioutil.ReadAll(contentReader)
@ -126,7 +126,7 @@ func (c Classifier) Classify(resolver source.FileResolver, location file.Locatio
} }
func filepathMatches(patterns []*regexp.Regexp, location file.Location) (bool, map[string]string) { func filepathMatches(patterns []*regexp.Regexp, location file.Location) (bool, map[string]string) {
for _, path := range []string{location.RealPath, location.VirtualPath} { for _, path := range []string{location.RealPath, location.AccessPath} {
if path == "" { if path == "" {
continue continue
} }

View File

@ -43,7 +43,7 @@ func TestFilepathMatches(t *testing.T) {
{ {
name: "virtual-filepath-match", name: "virtual-filepath-match",
location: file.Location{ location: file.Location{
VirtualPath: "/usr/bin/python2.7", AccessPath: "/usr/bin/python2.7",
}, },
patterns: []string{ patterns: []string{
`python([0-9]+\.[0-9]+)$`, `python([0-9]+\.[0-9]+)$`,
@ -53,7 +53,7 @@ func TestFilepathMatches(t *testing.T) {
{ {
name: "full-filepath-match", name: "full-filepath-match",
location: file.Location{ location: file.Location{
VirtualPath: "/usr/bin/python2.7", AccessPath: "/usr/bin/python2.7",
}, },
patterns: []string{ patterns: []string{
`.*/bin/python([0-9]+\.[0-9]+)$`, `.*/bin/python([0-9]+\.[0-9]+)$`,

View File

@ -72,7 +72,7 @@ func (i *Cataloger) catalogLocation(resolver source.FileResolver, location file.
if err != nil { if err != nil {
return "", err return "", err
} }
defer internal.CloseAndLogError(contentReader, location.VirtualPath) defer internal.CloseAndLogError(contentReader, location.AccessPath)
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
encoder := base64.NewEncoder(base64.StdEncoding, buf) encoder := base64.NewEncoder(base64.StdEncoding, buf)

View File

@ -72,7 +72,7 @@ func (i *Cataloger) catalogLocation(resolver source.FileResolver, location file.
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer internal.CloseAndLogError(contentReader, location.VirtualPath) defer internal.CloseAndLogError(contentReader, location.AccessPath)
// create a set of hasher objects tied together with a single writer to feed content into // create a set of hasher objects tied together with a single writer to feed content into
hashers := make([]hash.Hash, len(i.hashes)) hashers := make([]hash.Hash, len(i.hashes))

View File

@ -125,7 +125,7 @@ func extractValue(resolver source.FileResolver, location file.Location, start, l
if err != nil { if err != nil {
return "", fmt.Errorf("unable to fetch reader for location=%q : %w", location, err) 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(ioutil.Discard, readCloser, start) n, err := io.CopyN(ioutil.Discard, readCloser, start)
if err != nil { if err != nil {

View File

@ -20,7 +20,7 @@ func catalogLocationByLine(resolver source.FileResolver, location file.Location,
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to fetch reader for location=%q : %w", location, err) 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 scanner = bufio.NewReader(readCloser)
var position int64 var position int64
@ -69,7 +69,7 @@ func searchForSecretsWithinLine(resolver source.FileResolver, location file.Loca
if secret != nil { if secret != nil {
secrets = append(secrets, *secret) secrets = append(secrets, *secret)
} }
internal.CloseAndLogError(reader, location.VirtualPath) internal.CloseAndLogError(reader, location.AccessPath)
} }
} }

View File

@ -14,8 +14,8 @@ type Location struct {
Coordinates `cyclonedx:""` // Empty string here means there is no intermediate property name, e.g. syft:locations:0:path without "coordinates" 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) // 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) // 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 AccessPath 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. 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. // NewLocation creates a new Location representing a path without denoting a filesystem or FileCatalog reference.
@ -28,12 +28,12 @@ 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) // 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{ return Location{
Coordinates: Coordinates{ Coordinates: Coordinates{
RealPath: realPath, RealPath: realPath,
}, },
VirtualPath: virtualPath, AccessPath: accessPath,
} }
} }
@ -45,7 +45,7 @@ func NewLocationFromCoordinates(coordinates Coordinates) Location {
} }
// NewLocationFromImage creates a new Location representing the given path (extracted from the ref) relative to the given image. // NewLocationFromImage creates a new Location representing the given path (extracted from the ref) 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 {
entry, err := img.FileCatalog.Get(ref) entry, err := img.FileCatalog.Get(ref)
if err != nil { if err != nil {
log.Warnf("unable to find file catalog entry for ref=%+v", ref) log.Warnf("unable to find file catalog entry for ref=%+v", ref)
@ -53,8 +53,8 @@ func NewLocationFromImage(virtualPath string, ref file.Reference, img *image.Ima
Coordinates: Coordinates{ Coordinates: Coordinates{
RealPath: string(ref.RealPath), RealPath: string(ref.RealPath),
}, },
VirtualPath: virtualPath, AccessPath: accessPath,
ref: ref, ref: ref,
} }
} }
@ -63,8 +63,8 @@ func NewLocationFromImage(virtualPath string, ref file.Reference, img *image.Ima
RealPath: string(ref.RealPath), RealPath: string(ref.RealPath),
FileSystemID: entry.Layer.Metadata.Digest, FileSystemID: entry.Layer.Metadata.Digest,
}, },
VirtualPath: virtualPath, AccessPath: accessPath,
ref: ref, ref: ref,
} }
} }
@ -87,8 +87,8 @@ func NewVirtualLocationFromDirectory(responsePath, virtualResponsePath string, r
Coordinates: Coordinates{ Coordinates: Coordinates{
RealPath: responsePath, RealPath: responsePath,
}, },
VirtualPath: virtualResponsePath, AccessPath: virtualResponsePath,
ref: ref, ref: ref,
} }
} }
@ -100,8 +100,8 @@ func (l Location) String() string {
str += fmt.Sprintf("RealPath=%q", l.RealPath) str += fmt.Sprintf("RealPath=%q", l.RealPath)
if l.VirtualPath != "" { if l.AccessPath != "" {
str += fmt.Sprintf(" VirtualPath=%q", l.VirtualPath) str += fmt.Sprintf(" AccessPath=%q", l.AccessPath)
} }
if l.FileSystemID != "" { if l.FileSystemID != "" {

View File

@ -11,7 +11,7 @@ func TestLocation_ID(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
coordinates Coordinates coordinates Coordinates
virtualPath string accessPath string
ref file.Reference ref file.Reference
}{ }{
{ {
@ -27,7 +27,7 @@ func TestLocation_ID(t *testing.T) {
RealPath: "path!", RealPath: "path!",
FileSystemID: "filesystem!", FileSystemID: "filesystem!",
}, },
virtualPath: "virtualPath!", accessPath: "accessPath!",
ref: file.Reference{ ref: file.Reference{
RealPath: "other-real-path!", RealPath: "other-real-path!",
}, },
@ -37,7 +37,7 @@ func TestLocation_ID(t *testing.T) {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
l := Location{ l := Location{
Coordinates: test.coordinates, Coordinates: test.coordinates,
VirtualPath: test.virtualPath, AccessPath: test.accessPath,
ref: test.ref, ref: test.ref,
} }
assert.Equal(t, l.ID(), test.coordinates.ID()) assert.Equal(t, l.ID(), test.coordinates.ID())

View File

@ -69,7 +69,7 @@ func IdentifyRelease(resolver source.FileResolver) *Release {
} }
content, err := ioutil.ReadAll(contentReader) content, err := ioutil.ReadAll(contentReader)
internal.CloseAndLogError(contentReader, location.VirtualPath) internal.CloseAndLogError(contentReader, location.AccessPath)
if err != nil { if err != nil {
log.Warnf("unable to read %q: %+v", location.RealPath, err) log.Warnf("unable to read %q: %+v", location.RealPath, err)
break break

View File

@ -94,9 +94,9 @@ func (c *Catalog) Add(p Package) {
c.idsByPath[l.RealPath] = append(c.idsByPath[l.RealPath], id) c.idsByPath[l.RealPath] = append(c.idsByPath[l.RealPath], id)
observedPaths.Add(l.RealPath) observedPaths.Add(l.RealPath)
} }
if l.VirtualPath != "" && l.RealPath != l.VirtualPath && !observedPaths.Contains(l.VirtualPath) { if l.AccessPath != "" && l.RealPath != l.AccessPath && !observedPaths.Contains(l.AccessPath) {
c.idsByPath[l.VirtualPath] = append(c.idsByPath[l.VirtualPath], id) c.idsByPath[l.AccessPath] = append(c.idsByPath[l.AccessPath], id)
observedPaths.Add(l.VirtualPath) observedPaths.Add(l.AccessPath)
} }
} }
} }

View File

@ -53,7 +53,7 @@ func (c *Cataloger) Catalog(resolver source.FileResolver) ([]pkg.Package, []arti
} }
pkgs, err := parseDpkgStatus(dbContents) pkgs, err := parseDpkgStatus(dbContents)
internal.CloseAndLogError(dbContents, dbLocation.VirtualPath) internal.CloseAndLogError(dbContents, dbLocation.AccessPath)
if err != nil { if err != nil {
log.Warnf("dpkg cataloger: unable to catalog package=%+v: %w", dbLocation.RealPath, err) log.Warnf("dpkg cataloger: unable to catalog package=%+v: %w", dbLocation.RealPath, err)
continue continue
@ -85,7 +85,7 @@ func addLicenses(resolver source.FileResolver, dbLocation file.Location, p *pkg.
copyrightReader, copyrightLocation := fetchCopyrightContents(resolver, dbLocation, p) copyrightReader, copyrightLocation := fetchCopyrightContents(resolver, dbLocation, p)
if copyrightReader != nil && copyrightLocation != nil { if copyrightReader != nil && copyrightLocation != nil {
defer internal.CloseAndLogError(copyrightReader, copyrightLocation.VirtualPath) defer internal.CloseAndLogError(copyrightReader, copyrightLocation.AccessPath)
// attach the licenses // attach the licenses
p.Licenses = parseLicensesFromCopyright(copyrightReader) p.Licenses = parseLicensesFromCopyright(copyrightReader)
@ -130,7 +130,7 @@ func getAdditionalFileListing(resolver source.FileResolver, dbLocation file.Loca
md5Reader, md5Location := fetchMd5Contents(resolver, dbLocation, p) md5Reader, md5Location := fetchMd5Contents(resolver, dbLocation, p)
if md5Reader != nil && md5Location != nil { if md5Reader != nil && md5Location != nil {
defer internal.CloseAndLogError(md5Reader, md5Location.VirtualPath) defer internal.CloseAndLogError(md5Reader, md5Location.AccessPath)
// attach the file list // attach the file list
files = append(files, parseDpkgMD5Info(md5Reader)...) files = append(files, parseDpkgMD5Info(md5Reader)...)
@ -141,7 +141,7 @@ func getAdditionalFileListing(resolver source.FileResolver, dbLocation file.Loca
conffilesReader, conffilesLocation := fetchConffileContents(resolver, dbLocation, p) conffilesReader, conffilesLocation := fetchConffileContents(resolver, dbLocation, p)
if conffilesReader != nil && conffilesLocation != nil { if conffilesReader != nil && conffilesLocation != nil {
defer internal.CloseAndLogError(conffilesReader, conffilesLocation.VirtualPath) defer internal.CloseAndLogError(conffilesReader, conffilesLocation.AccessPath)
// attach the file list // attach the file list
files = append(files, parseDpkgConffileInfo(conffilesReader)...) files = append(files, parseDpkgConffileInfo(conffilesReader)...)

View File

@ -51,7 +51,7 @@ func (c *Cataloger) Catalog(resolver source.FileResolver) ([]pkg.Package, []arti
} }
discoveredPackages, discoveredRelationships, err := parser(location.RealPath, contentReader) discoveredPackages, discoveredRelationships, err := parser(location.RealPath, contentReader)
internal.CloseAndLogError(contentReader, location.VirtualPath) internal.CloseAndLogError(contentReader, location.AccessPath)
if err != nil { if err != nil {
// TODO: should we fail? or only log? // TODO: should we fail? or only log?
log.Warnf("cataloger '%s' failed to parse entries at location=%+v: %+v", c.upstreamCataloger, location, err) log.Warnf("cataloger '%s' failed to parse entries at location=%+v: %+v", c.upstreamCataloger, location, err)

View File

@ -142,7 +142,7 @@ func (c *PackageCataloger) fetchTopLevelPackages(resolver source.FileResolver, m
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
defer internal.CloseAndLogError(topLevelContents, topLevelLocation.VirtualPath) defer internal.CloseAndLogError(topLevelContents, topLevelLocation.AccessPath)
scanner := bufio.NewScanner(topLevelContents) scanner := bufio.NewScanner(topLevelContents)
for scanner.Scan() { for scanner.Scan() {
@ -171,7 +171,7 @@ func (c *PackageCataloger) fetchDirectURLData(resolver source.FileResolver, meta
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
defer internal.CloseAndLogError(directURLContents, directURLLocation.VirtualPath) defer internal.CloseAndLogError(directURLContents, directURLLocation.AccessPath)
buffer, err := ioutil.ReadAll(directURLContents) buffer, err := ioutil.ReadAll(directURLContents)
if err != nil { if err != nil {
@ -198,7 +198,7 @@ func (c *PackageCataloger) assembleEggOrWheelMetadata(resolver source.FileResolv
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
defer internal.CloseAndLogError(metadataContents, metadataLocation.VirtualPath) defer internal.CloseAndLogError(metadataContents, metadataLocation.AccessPath)
metadata, err := parseWheelOrEggMetadata(metadataLocation.RealPath, metadataContents) metadata, err := parseWheelOrEggMetadata(metadataLocation.RealPath, metadataContents)
if err != nil { if err != nil {

View File

@ -42,7 +42,7 @@ func (c *Cataloger) Catalog(resolver source.FileResolver) ([]pkg.Package, []arti
} }
discoveredPkgs, err := parseRpmDB(resolver, location, dbContentReader) discoveredPkgs, err := parseRpmDB(resolver, location, dbContentReader)
internal.CloseAndLogError(dbContentReader, location.VirtualPath) internal.CloseAndLogError(dbContentReader, location.AccessPath)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("unable to catalog rpmdb package=%+v: %w", location.RealPath, err) return nil, nil, fmt.Errorf("unable to catalog rpmdb package=%+v: %w", location.RealPath, err)
} }

View File

@ -18,7 +18,7 @@ func TestFingerprint(t *testing.T) {
RealPath: "39.0742° N, 21.8243° E", RealPath: "39.0742° N, 21.8243° E",
FileSystemID: "Earth", FileSystemID: "Earth",
}, },
VirtualPath: "/Ancient-Greece", AccessPath: "/Ancient-Greece",
}, },
}, },
Licenses: []string{ Licenses: []string{

View File

@ -193,10 +193,10 @@ func (r *allLayersResolver) FileContentsByLocation(location file.Location) (io.R
switch entry.Metadata.TypeFlag { switch entry.Metadata.TypeFlag {
case tar.TypeSymlink, tar.TypeLink: case tar.TypeSymlink, tar.TypeLink:
// the location we are searching may be a symlink, we should always work with the resolved file // the location we are searching may be a symlink, we should always work with the resolved file
newLocation := r.RelativeFileByPath(location, location.VirtualPath) newLocation := r.RelativeFileByPath(location, location.AccessPath)
if newLocation == nil { if newLocation == nil {
// this is a dead link // this is a dead link
return nil, fmt.Errorf("no contents for location=%q", location.VirtualPath) return nil, fmt.Errorf("no contents for location=%q", location.AccessPath)
} }
location = *newLocation location = *newLocation
} }

View File

@ -381,59 +381,59 @@ func Test_imageAllLayersResolver_resolvesLinks(t *testing.T) {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/etc/group", RealPath: "/etc/group",
}, },
VirtualPath: "/etc/group", AccessPath: "/etc/group",
}, },
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/etc/passwd", RealPath: "/etc/passwd",
}, },
VirtualPath: "/etc/passwd", AccessPath: "/etc/passwd",
}, },
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/etc/shadow", RealPath: "/etc/shadow",
}, },
VirtualPath: "/etc/shadow", AccessPath: "/etc/shadow",
}, },
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-1.txt", RealPath: "/file-1.txt",
}, },
VirtualPath: "/file-1.txt", AccessPath: "/file-1.txt",
}, },
// copy 1 // copy 1
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-2.txt", RealPath: "/file-2.txt",
}, },
VirtualPath: "/file-2.txt", AccessPath: "/file-2.txt",
}, },
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-3.txt", RealPath: "/file-3.txt",
}, },
VirtualPath: "/file-3.txt", AccessPath: "/file-3.txt",
}, },
// copy 2 // copy 2
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-2.txt", RealPath: "/file-2.txt",
}, },
VirtualPath: "/file-2.txt", AccessPath: "/file-2.txt",
}, },
// copy 1 // copy 1
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/parent/file-4.txt", RealPath: "/parent/file-4.txt",
}, },
VirtualPath: "/parent/file-4.txt", AccessPath: "/parent/file-4.txt",
}, },
// copy 2 // copy 2
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/parent/file-4.txt", RealPath: "/parent/file-4.txt",
}, },
VirtualPath: "/parent/file-4.txt", AccessPath: "/parent/file-4.txt",
}, },
}, },
}, },
@ -450,27 +450,27 @@ func Test_imageAllLayersResolver_resolvesLinks(t *testing.T) {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-1.txt", RealPath: "/file-1.txt",
}, },
VirtualPath: "/link-1", AccessPath: "/link-1",
}, },
// copy 1 // copy 1
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-2.txt", RealPath: "/file-2.txt",
}, },
VirtualPath: "/link-2", AccessPath: "/link-2",
}, },
// copy 2 // copy 2
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-2.txt", RealPath: "/file-2.txt",
}, },
VirtualPath: "/link-2", AccessPath: "/link-2",
}, },
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-3.txt", RealPath: "/file-3.txt",
}, },
VirtualPath: "/link-within", AccessPath: "/link-within",
}, },
}, },
}, },
@ -488,13 +488,13 @@ func Test_imageAllLayersResolver_resolvesLinks(t *testing.T) {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-2.txt", RealPath: "/file-2.txt",
}, },
VirtualPath: "/link-2", AccessPath: "/link-2",
}, },
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-2.txt", RealPath: "/file-2.txt",
}, },
VirtualPath: "/link-2", AccessPath: "/link-2",
}, },
}, },
}, },
@ -512,13 +512,13 @@ func Test_imageAllLayersResolver_resolvesLinks(t *testing.T) {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-2.txt", RealPath: "/file-2.txt",
}, },
VirtualPath: "/link-indirect", AccessPath: "/link-indirect",
}, },
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-2.txt", RealPath: "/file-2.txt",
}, },
VirtualPath: "/link-indirect", AccessPath: "/link-indirect",
}, },
}, },
}, },
@ -536,7 +536,7 @@ func Test_imageAllLayersResolver_resolvesLinks(t *testing.T) {
assert.Len(t, actualLocations, len(test.expected)) assert.Len(t, actualLocations, len(test.expected))
for i, actual := range actualLocations { for i, actual := range actualLocations {
assert.Equal(t, test.expected[i].RealPath, actual.RealPath) assert.Equal(t, test.expected[i].RealPath, actual.RealPath)
assert.Equal(t, test.expected[i].VirtualPath, actual.VirtualPath) assert.Equal(t, test.expected[i].AccessPath, actual.AccessPath)
} }
}) })
} }

View File

@ -10,8 +10,8 @@ import (
func Test_allRegularFiles(t *testing.T) { func Test_allRegularFiles(t *testing.T) {
type access struct { type access struct {
realPath string realPath string
virtualPath string accessPath string
} }
tests := []struct { tests := []struct {
name string name string
@ -56,8 +56,8 @@ func Test_allRegularFiles(t *testing.T) {
virtualLocations := strset.New() virtualLocations := strset.New()
for _, l := range locations { for _, l := range locations {
realLocations.Add(l.RealPath) realLocations.Add(l.RealPath)
if l.VirtualPath != "" { if l.AccessPath != "" {
virtualLocations.Add(l.VirtualPath) virtualLocations.Add(l.AccessPath)
} }
} }
assert.ElementsMatch(t, tt.wantRealPaths.List(), realLocations.List(), "mismatched real paths") assert.ElementsMatch(t, tt.wantRealPaths.List(), realLocations.List(), "mismatched real paths")

View File

@ -261,7 +261,7 @@ func (r directoryResolver) addSymlinkToIndex(p string, info os.FileInfo) (string
} }
location := file.NewLocationFromDirectory(p, *ref) location := file.NewLocationFromDirectory(p, *ref)
location.VirtualPath = p location.AccessPath = p
metadata := file.MetadataFromPath(p, usedInfo, r.isInIndex(location)) metadata := file.MetadataFromPath(p, usedInfo, r.isInIndex(location))
metadata.LinkDestination = linkTarget metadata.LinkDestination = linkTarget
r.addFileMetadataToIndex(ref, metadata) r.addFileMetadataToIndex(ref, metadata)

View File

@ -634,14 +634,14 @@ func Test_IndexingNestedSymLinks(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Len(t, locations, 1) require.Len(t, locations, 1)
assert.Equal(t, "readme", locations[0].RealPath) assert.Equal(t, "readme", locations[0].RealPath)
assert.Equal(t, "link_to_new_readme", locations[0].VirtualPath) assert.Equal(t, "link_to_new_readme", locations[0].AccessPath)
// check that we can access the same file via 2 symlinks // check that we can access the same file via 2 symlinks
locations, err = resolver.FilesByPath("./link_to_link_to_new_readme") locations, err = resolver.FilesByPath("./link_to_link_to_new_readme")
require.NoError(t, err) require.NoError(t, err)
require.Len(t, locations, 1) require.Len(t, locations, 1)
assert.Equal(t, "readme", locations[0].RealPath) assert.Equal(t, "readme", locations[0].RealPath)
assert.Equal(t, "link_to_link_to_new_readme", locations[0].VirtualPath) assert.Equal(t, "link_to_link_to_new_readme", locations[0].AccessPath)
// check that we can access the same file via 2 symlinks // check that we can access the same file via 2 symlinks
locations, err = resolver.FilesByGlob("**/link_*") locations, err = resolver.FilesByGlob("**/link_*")
@ -661,7 +661,7 @@ func Test_IndexingNestedSymLinks(t *testing.T) {
actualRealPaths := strset.New() actualRealPaths := strset.New()
actualVirtualPaths := strset.New() actualVirtualPaths := strset.New()
for _, a := range locations { for _, a := range locations {
actualVirtualPaths.Add(a.VirtualPath) actualVirtualPaths.Add(a.AccessPath)
actualRealPaths.Add(a.RealPath) actualRealPaths.Add(a.RealPath)
} }

View File

@ -83,7 +83,7 @@ func (r *excludingResolver) AllLocations() <-chan file.Location {
} }
func locationMatches(location *file.Location, exclusionFn excludeFn) bool { func locationMatches(location *file.Location, exclusionFn excludeFn) bool {
return exclusionFn(location.RealPath) || exclusionFn(location.VirtualPath) return exclusionFn(location.RealPath) || exclusionFn(location.AccessPath)
} }
func filterLocations(locations []file.Location, err error, exclusionFn excludeFn) ([]file.Location, error) { func filterLocations(locations []file.Location, err error, exclusionFn excludeFn) ([]file.Location, error) {

View File

@ -124,7 +124,7 @@ func makeLocation(path string) file.Location {
RealPath: path, RealPath: path,
FileSystemID: "", FileSystemID: "",
}, },
VirtualPath: "", AccessPath: "",
} }
} }

View File

@ -364,43 +364,43 @@ func Test_imageSquashResolver_resolvesLinks(t *testing.T) {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/etc/group", RealPath: "/etc/group",
}, },
VirtualPath: "/etc/group", AccessPath: "/etc/group",
}, },
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/etc/passwd", RealPath: "/etc/passwd",
}, },
VirtualPath: "/etc/passwd", AccessPath: "/etc/passwd",
}, },
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/etc/shadow", RealPath: "/etc/shadow",
}, },
VirtualPath: "/etc/shadow", AccessPath: "/etc/shadow",
}, },
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-1.txt", RealPath: "/file-1.txt",
}, },
VirtualPath: "/file-1.txt", AccessPath: "/file-1.txt",
}, },
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-3.txt", RealPath: "/file-3.txt",
}, },
VirtualPath: "/file-3.txt", AccessPath: "/file-3.txt",
}, },
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-2.txt", RealPath: "/file-2.txt",
}, },
VirtualPath: "/file-2.txt", AccessPath: "/file-2.txt",
}, },
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/parent/file-4.txt", RealPath: "/parent/file-4.txt",
}, },
VirtualPath: "/parent/file-4.txt", AccessPath: "/parent/file-4.txt",
}, },
}, },
}, },
@ -417,19 +417,19 @@ func Test_imageSquashResolver_resolvesLinks(t *testing.T) {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-3.txt", RealPath: "/file-3.txt",
}, },
VirtualPath: "/link-within", AccessPath: "/link-within",
}, },
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-2.txt", RealPath: "/file-2.txt",
}, },
VirtualPath: "/link-2", AccessPath: "/link-2",
}, },
{ {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-1.txt", RealPath: "/file-1.txt",
}, },
VirtualPath: "/link-1", AccessPath: "/link-1",
}, },
}, },
}, },
@ -447,7 +447,7 @@ func Test_imageSquashResolver_resolvesLinks(t *testing.T) {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-2.txt", RealPath: "/file-2.txt",
}, },
VirtualPath: "/link-2", AccessPath: "/link-2",
}, },
}, },
}, },
@ -465,7 +465,7 @@ func Test_imageSquashResolver_resolvesLinks(t *testing.T) {
Coordinates: file.Coordinates{ Coordinates: file.Coordinates{
RealPath: "/file-2.txt", RealPath: "/file-2.txt",
}, },
VirtualPath: "/link-indirect", AccessPath: "/link-indirect",
}, },
}, },
}, },
@ -486,12 +486,12 @@ func Test_imageSquashResolver_resolvesLinks(t *testing.T) {
expectedMap := make(map[string]string) expectedMap := make(map[string]string)
for _, e := range test.expected { for _, e := range test.expected {
expectedMap[e.VirtualPath] = e.RealPath expectedMap[e.AccessPath] = e.RealPath
} }
actualMap := make(map[string]string) actualMap := make(map[string]string)
for _, a := range test.expected { for _, a := range test.expected {
actualMap[a.VirtualPath] = a.RealPath actualMap[a.AccessPath] = a.RealPath
} }
assert.Equal(t, expectedMap, actualMap) assert.Equal(t, expectedMap, actualMap)