rename file.Location.VirtualPath to AccessPath (#2288)

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
Alex Goodman 2023-11-09 11:30:08 -06:00 committed by GitHub
parent baa3dc74d3
commit 3f13d209a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 320 additions and 320 deletions

View File

@ -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)

View File

@ -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 {

View File

@ -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()))
})
}
}

View File

@ -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 {

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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",
},
}

View File

@ -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,
},
}

View File

@ -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
}

View File

@ -636,7 +636,7 @@ func Test_directPackageFiles(t *testing.T) {
RealPath: "some-file",
FileSystemID: "",
},
VirtualPath: "some-file",
AccessPath: "some-file",
},
LocationMetadata: file.LocationMetadata{
Annotations: map[string]string{},

View File

@ -111,8 +111,8 @@ func toPath(s source.Description, p pkg.Package) string {
if len(locations) > 0 {
location := locations[0]
packagePath := location.RealPath
if location.VirtualPath != "" {
packagePath = location.VirtualPath
if location.AccessPath != "" {
packagePath = location.AccessPath
}
packagePath = strings.TrimPrefix(packagePath, "/")
switch metadata := s.Metadata.(type) {

View File

@ -123,7 +123,7 @@ FileCopyrightText: NOASSERTION
f = file.Location{
LocationData: file.LocationData{
Coordinates: c,
VirtualPath: "",
AccessPath: "",
},
LocationMetadata: file.LocationMetadata{},
}

View File

@ -80,7 +80,7 @@ func Test_EncodeDecodeCycle(t *testing.T) {
}
for _, d := range deep.Equal(p, actualPackages[idx]) {
if strings.Contains(d, ".VirtualPath: ") {
if strings.Contains(d, ".AccessPath: ") {
// location.Virtual path is not exposed in the json output
continue
}

View File

@ -193,10 +193,10 @@ func (r *ContainerImageAllLayers) FileContentsByLocation(location file.Location)
switch entry.Metadata.Type {
case stereoscopeFile.TypeSymLink, stereoscopeFile.TypeHardLink:
// 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 {
// 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
case stereoscopeFile.TypeDirectory:

View File

@ -110,7 +110,7 @@ func (r Directory) FilesByPath(userPaths ...string) ([]file.Location, error) {
continue
}
// we should be resolving symlinks and preserving this information as a VirtualPath to the real file
// we should be resolving symlinks and preserving this information as a AccessPath to the real file
ref, err := r.searchContext.SearchByPath(userStrPath, filetree.FollowBasenameLinks)
if err != nil {
log.Tracef("unable to evaluate symlink for path=%q : %+v", userPath, err)

View File

@ -65,13 +65,13 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
t.Cleanup(cleanup)
cases := []struct {
name string
cwd string
root string
base string
input string
expectedRealPath string
expectedVirtualPath string // note: if empty it will be assumed to match the expectedRealPath
name string
cwd string
root string
base string
input string
expectedRealPath string
expectedAccessPath string // note: if empty it will be assumed to match the expectedRealPath
}{
{
name: "relative root, relative request, direct",
@ -139,7 +139,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "path/to/the/file.txt",
expectedVirtualPath: "path/to/the/file.txt",
expectedAccessPath: "path/to/the/file.txt",
},
{
name: "abs root, relative request, direct, cwd within symlink root",
@ -159,7 +159,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "path/to/the/file.txt",
expectedVirtualPath: "path/to/the/file.txt",
expectedAccessPath: "path/to/the/file.txt",
},
{
name: "abs root, abs request, direct, cwd within symlink root",
@ -180,7 +180,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "to/the/file.txt",
expectedVirtualPath: "to/the/file.txt",
expectedAccessPath: "to/the/file.txt",
},
{
name: "abs root, relative nested request, direct, cwd within symlink root",
@ -200,7 +200,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "to/the/file.txt",
expectedVirtualPath: "to/the/file.txt",
expectedAccessPath: "to/the/file.txt",
},
{
name: "abs root, abs nested request, direct, cwd within symlink root",
@ -221,7 +221,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "path/to/the/file.txt",
expectedVirtualPath: "path/to/the/file.txt",
expectedAccessPath: "path/to/the/file.txt",
},
{
name: "abs root, relative request, direct, cwd within (double) symlink root",
@ -241,7 +241,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "path/to/the/file.txt",
expectedVirtualPath: "path/to/the/file.txt",
expectedAccessPath: "path/to/the/file.txt",
},
{
name: "abs root, abs request, direct, cwd within (double) symlink root",
@ -262,7 +262,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "to/the/file.txt",
expectedVirtualPath: "to/the/file.txt",
expectedAccessPath: "to/the/file.txt",
},
{
name: "abs root, relative nested request, direct, cwd within (double) symlink root",
@ -282,7 +282,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "to/the/file.txt",
expectedVirtualPath: "to/the/file.txt",
expectedAccessPath: "to/the/file.txt",
},
{
name: "abs root, abs nested request, direct, cwd within (double) symlink root",
@ -303,7 +303,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "to/the/file.txt",
expectedVirtualPath: "to/the/file.txt",
expectedAccessPath: "to/the/file.txt",
},
{
name: "abs root, relative nested request, direct, cwd deep within (double) symlink root",
@ -323,7 +323,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "to/the/file.txt",
expectedVirtualPath: "to/the/file.txt",
expectedAccessPath: "to/the/file.txt",
},
{
name: "abs root, abs nested request, direct, cwd deep within (double) symlink root",
@ -334,163 +334,163 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
},
// link to outside of root cases...
{
name: "relative root, relative request, abs indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "relative root, relative request, abs indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "abs root, relative request, abs indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "abs root, relative request, abs indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "relative root, abs request, abs indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "relative root, abs request, abs indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "abs root, abs request, abs indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "abs root, abs request, abs indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "relative root, relative request, relative indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "relative root, relative request, relative indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, relative request, relative indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "abs root, relative request, relative indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "relative root, abs request, relative indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "relative root, abs request, relative indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, abs request, relative indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "abs root, abs request, relative indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
// link to outside of root cases... cwd within symlink root
{
name: "relative root, relative request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "relative root, relative request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "abs root, relative request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "abs root, relative request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "relative root, abs request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "relative root, abs request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "abs root, abs request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "abs root, abs request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "relative root, relative request, relative indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "relative root, relative request, relative indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, relative request, relative indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "abs root, relative request, relative indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "relative root, abs request, relative indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "relative root, abs request, relative indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, abs request, relative indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "abs root, abs request, relative indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "relative root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
cwd: relativeViaDoubleLink,
root: "path",
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "relative root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
cwd: relativeViaDoubleLink,
root: "path",
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
cwd: relativeViaDoubleLink,
root: filepath.Join(absolute, "path"),
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "abs root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
cwd: relativeViaDoubleLink,
root: filepath.Join(absolute, "path"),
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "relative root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
cwd: relativeViaDoubleLink,
root: "path",
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "relative root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
cwd: relativeViaDoubleLink,
root: "path",
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
cwd: relativeViaDoubleLink,
root: filepath.Join(absolute, "path"),
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "abs root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
cwd: relativeViaDoubleLink,
root: filepath.Join(absolute, "path"),
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
if c.expectedVirtualPath == "" {
c.expectedVirtualPath = c.expectedRealPath
if c.expectedAccessPath == "" {
c.expectedAccessPath = c.expectedRealPath
}
// we need to mimic a shell, otherwise we won't get a path within a symlink
@ -515,7 +515,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
}
require.Len(t, refs, 1)
assert.Equal(t, c.expectedRealPath, refs[0].RealPath, "real path different")
assert.Equal(t, c.expectedVirtualPath, refs[0].VirtualPath, "virtual path different")
assert.Equal(t, c.expectedAccessPath, refs[0].AccessPath, "virtual path different")
})
}
}
@ -961,14 +961,14 @@ func Test_IndexingNestedSymLinks(t *testing.T) {
require.NoError(t, err)
require.Len(t, locations, 1)
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
locations, err = resolver.FilesByPath("./link_to_link_to_new_readme")
require.NoError(t, err)
require.Len(t, locations, 1)
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
locations, err = resolver.FilesByGlob("**/link_*")
@ -976,7 +976,7 @@ func Test_IndexingNestedSymLinks(t *testing.T) {
require.Len(t, locations, 1) // you would think this is 2, however, they point to the same file, and glob only returns unique files
// returned locations can be in any order
expectedVirtualPaths := []string{
expectedAccessPaths := []string{
"link_to_link_to_new_readme",
//"link_to_new_readme", // we filter out this one because the first symlink resolves to the same file
}
@ -986,13 +986,13 @@ func Test_IndexingNestedSymLinks(t *testing.T) {
}
actualRealPaths := strset.New()
actualVirtualPaths := strset.New()
actualAccessPaths := strset.New()
for _, a := range locations {
actualVirtualPaths.Add(a.VirtualPath)
actualAccessPaths.Add(a.AccessPath)
actualRealPaths.Add(a.RealPath)
}
assert.ElementsMatch(t, expectedVirtualPaths, actualVirtualPaths.List())
assert.ElementsMatch(t, expectedAccessPaths, actualAccessPaths.List())
assert.ElementsMatch(t, expectedRealPaths, actualRealPaths.List())
}

View File

@ -83,7 +83,7 @@ func (r *excluding) AllLocations() <-chan file.Location {
}
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) {

View File

@ -165,8 +165,8 @@ nextPath:
for i := range out {
existing := &out[i]
if existing.RealPath == l.RealPath {
if l.VirtualPath == "" {
existing.VirtualPath = ""
if l.AccessPath == "" {
existing.AccessPath = ""
}
continue nextPath
}

View File

@ -90,13 +90,13 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
t.Cleanup(cleanup)
cases := []struct {
name string
cwd string
root string
base string
input string
expectedRealPath string
expectedVirtualPath string // if empty, the virtual path should be the same as the real path
name string
cwd string
root string
base string
input string
expectedRealPath string
expectedAccessPath string // if empty, the virtual path should be the same as the real path
}{
{
name: "relative root, relative request, direct",
@ -319,32 +319,32 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
},
// link to outside of root cases...
{
name: "relative root, relative request, abs indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "relative root, relative request, abs indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "abs root, relative request, abs indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "abs root, relative request, abs indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "relative root, abs request, abs indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "relative root, abs request, abs indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "abs root, abs request, abs indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "abs root, abs request, abs indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "relative root, relative request, relative indirect (outside of root)",
@ -352,8 +352,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, relative request, relative indirect (outside of root)",
@ -361,8 +361,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "relative root, abs request, relative indirect (outside of root)",
@ -370,8 +370,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "/to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, abs request, relative indirect (outside of root)",
@ -379,41 +379,41 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "/to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
// link to outside of root cases... cwd within symlink root
{
name: "relative root, relative request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "relative root, relative request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "abs root, relative request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "abs root, relative request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "relative root, abs request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "relative root, abs request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "abs root, abs request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "abs root, abs request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "relative root, relative request, relative indirect (outside of root), cwd within symlink root",
@ -422,8 +422,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, relative request, relative indirect (outside of root), cwd within symlink root",
@ -432,8 +432,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "relative root, abs request, relative indirect (outside of root), cwd within symlink root",
@ -442,8 +442,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "/to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, abs request, relative indirect (outside of root), cwd within symlink root",
@ -452,8 +452,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "/to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "relative root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
@ -462,8 +462,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
@ -472,8 +472,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "relative root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
@ -482,8 +482,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "/to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
@ -492,14 +492,14 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "/to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
if c.expectedVirtualPath == "" {
c.expectedVirtualPath = c.expectedRealPath
if c.expectedAccessPath == "" {
c.expectedAccessPath = c.expectedRealPath
}
// we need to mimic a shell, otherwise we won't get a path within a symlink
@ -523,7 +523,7 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
}
require.Len(t, refs, 1)
assert.Equal(t, c.expectedRealPath, refs[0].RealPath, "real path different")
assert.Equal(t, c.expectedVirtualPath, refs[0].VirtualPath, "virtual path different")
assert.Equal(t, c.expectedAccessPath, refs[0].AccessPath, "virtual path different")
})
}
}
@ -847,14 +847,14 @@ func Test_UnindexedDirectoryResover_IndexingNestedSymLinks(t *testing.T) {
require.NoError(t, err)
require.Len(t, locations, 1)
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
locations, err = resolver.FilesByPath("./link_to_link_to_new_readme")
require.NoError(t, err)
require.Len(t, locations, 1)
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
locations, err = resolver.FilesByGlob("**/link_*")
@ -862,7 +862,7 @@ func Test_UnindexedDirectoryResover_IndexingNestedSymLinks(t *testing.T) {
require.Len(t, locations, 1) // you would think this is 2, however, they point to the same file, and glob only returns unique files
// returned locations can be in any order
expectedVirtualPaths := []string{
expectedAccessPaths := []string{
"link_to_link_to_new_readme",
//"link_to_new_readme", // we filter out this one because the first symlink resolves to the same file
}
@ -872,13 +872,13 @@ func Test_UnindexedDirectoryResover_IndexingNestedSymLinks(t *testing.T) {
}
actualRealPaths := strset.New()
actualVirtualPaths := strset.New()
actualAccessPaths := strset.New()
for _, a := range locations {
actualVirtualPaths.Add(a.VirtualPath)
actualAccessPaths.Add(a.AccessPath)
actualRealPaths.Add(a.RealPath)
}
assert.ElementsMatch(t, expectedVirtualPaths, actualVirtualPaths.List())
assert.ElementsMatch(t, expectedAccessPaths, actualAccessPaths.List())
assert.ElementsMatch(t, expectedRealPaths, actualRealPaths.List())
}

View File

@ -71,7 +71,7 @@ func IdentifyRelease(resolver file.Resolver) *Release {
}
content, err := io.ReadAll(contentReader)
internal.CloseAndLogError(contentReader, location.VirtualPath)
internal.CloseAndLogError(contentReader, location.AccessPath)
if err != nil {
logger.WithFields("error", err, "path", location.RealPath).Trace("unable to read contents")
continue

View File

@ -130,9 +130,9 @@ func (c *Collection) addPathsToIndex(p Package) {
c.addPathToIndex(p.id, l.RealPath)
observedPaths.Add(l.RealPath)
}
if l.VirtualPath != "" && l.RealPath != l.VirtualPath && !observedPaths.Has(l.VirtualPath) {
c.addPathToIndex(p.id, l.VirtualPath)
observedPaths.Add(l.VirtualPath)
if l.AccessPath != "" && l.RealPath != l.AccessPath && !observedPaths.Has(l.AccessPath) {
c.addPathToIndex(p.id, l.AccessPath)
observedPaths.Add(l.AccessPath)
}
}
}
@ -179,9 +179,9 @@ func (c *Collection) deletePathsFromIndex(p Package) {
c.deletePathFromIndex(p.id, l.RealPath)
observedPaths.Add(l.RealPath)
}
if l.VirtualPath != "" && l.RealPath != l.VirtualPath && !observedPaths.Has(l.VirtualPath) {
c.deletePathFromIndex(p.id, l.VirtualPath)
observedPaths.Add(l.VirtualPath)
if l.AccessPath != "" && l.RealPath != l.AccessPath && !observedPaths.Has(l.AccessPath) {
c.deletePathFromIndex(p.id, l.AccessPath)
observedPaths.Add(l.AccessPath)
}
}
}

View File

@ -833,7 +833,7 @@ func assertPackagesAreEqual(t *testing.T, expected pkg.Package, p pkg.Package) {
matches = false
break
}
if m1.Location.VirtualPath != "" && m1.Location.VirtualPath != m2.Location.VirtualPath {
if m1.Location.AccessPath != "" && m1.Location.AccessPath != m2.Location.AccessPath {
matches = false
break
}

View File

@ -17,7 +17,7 @@ import (
var _ generic.Parser = parseConaninfo
func parseConanMetadataFromFilePath(path string) (pkg.ConaninfoEntry, error) {
// fullFilePath = str(reader.Location.VirtualPath)
// fullFilePath = str(reader.Location.AccessPath)
// Split the full patch into the folders we expect. I.e.:
// $HOME/.conan/data/<pkg-name>/<pkg-version>/<user>/<channel>/package/<package_id>/conaninfo.txt
re := regexp.MustCompile(`.*[/\\](?P<name>[^/\\]+)[/\\](?P<version>[^/\\]+)[/\\](?P<user>[^/\\]+)[/\\](?P<channel>[^/\\]+)[/\\]package[/\\](?P<id>[^/\\]+)[/\\]conaninfo\.txt`)

View File

@ -96,7 +96,7 @@ func addLicenses(resolver file.Resolver, dbLocation file.Location, p *pkg.Packag
copyrightReader, copyrightLocation := fetchCopyrightContents(resolver, dbLocation, metadata)
if copyrightReader != nil && copyrightLocation != nil {
defer internal.CloseAndLogError(copyrightReader, copyrightLocation.VirtualPath)
defer internal.CloseAndLogError(copyrightReader, copyrightLocation.AccessPath)
// attach the licenses
licenseStrs := parseLicensesFromCopyright(copyrightReader)
for _, licenseStr := range licenseStrs {
@ -147,7 +147,7 @@ func getAdditionalFileListing(resolver file.Resolver, dbLocation file.Location,
md5Reader, md5Location := fetchMd5Contents(resolver, dbLocation, m)
if md5Reader != nil && md5Location != nil {
defer internal.CloseAndLogError(md5Reader, md5Location.VirtualPath)
defer internal.CloseAndLogError(md5Reader, md5Location.AccessPath)
// attach the file list
files = append(files, parseDpkgMD5Info(md5Reader)...)
@ -158,7 +158,7 @@ func getAdditionalFileListing(resolver file.Resolver, dbLocation file.Location,
conffilesReader, conffilesLocation := fetchConffileContents(resolver, dbLocation, m)
if conffilesReader != nil && conffilesLocation != nil {
defer internal.CloseAndLogError(conffilesReader, conffilesLocation.VirtualPath)
defer internal.CloseAndLogError(conffilesReader, conffilesLocation.AccessPath)
// attach the file list
files = append(files, parseDpkgConffileInfo(conffilesReader)...)

View File

@ -49,9 +49,9 @@ func parseDotnetDeps(_ file.Resolver, _ *generic.Environment, reader file.Locati
return nil, nil, fmt.Errorf("failed to parse deps.json file: %w", err)
}
rootName := getDepsJSONFilePrefix(reader.AccessPath())
rootName := getDepsJSONFilePrefix(reader.Path())
if rootName == "" {
return nil, nil, fmt.Errorf("unable to determine root package name from deps.json file: %s", reader.AccessPath())
return nil, nil, fmt.Errorf("unable to determine root package name from deps.json file: %s", reader.Path())
}
var rootPkg *pkg.Package
for nameVersion, lib := range depsDoc.Libraries {
@ -65,7 +65,7 @@ func parseDotnetDeps(_ file.Resolver, _ *generic.Environment, reader file.Locati
}
}
if rootPkg == nil {
return nil, nil, fmt.Errorf("unable to determine root package from deps.json file: %s", reader.AccessPath())
return nil, nil, fmt.Errorf("unable to determine root package from deps.json file: %s", reader.Path())
}
pkgs = append(pkgs, *rootPkg)
pkgMap[createNameAndVersion(rootPkg.Name, rootPkg.Version)] = *rootPkg

View File

@ -127,7 +127,7 @@ func (c *Cataloger) Catalog(resolver file.Resolver) ([]pkg.Package, []artifact.R
}
discoveredPackages, discoveredRelationships, err := parser(resolver, &env, file.NewLocationReadCloser(location, contentReader))
internal.CloseAndLogError(contentReader, location.VirtualPath)
internal.CloseAndLogError(contentReader, location.AccessPath)
if err != nil {
logger.WithFields("location", location.RealPath, "error", err).Warnf("cataloger failed")
continue

View File

@ -16,7 +16,7 @@ import (
func Test_Cataloger(t *testing.T) {
allParsedPaths := make(map[string]bool)
parser := func(resolver file.Resolver, env *Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
allParsedPaths[reader.AccessPath()] = true
allParsedPaths[reader.Path()] = true
contents, err := io.ReadAll(reader)
require.NoError(t, err)

View File

@ -61,7 +61,7 @@ func NewCatalogTester() *CatalogTester {
}
func DefaultLocationComparer(x, y file.Location) bool {
return cmp.Equal(x.Coordinates, y.Coordinates) && cmp.Equal(x.VirtualPath, y.VirtualPath)
return cmp.Equal(x.Coordinates, y.Coordinates) && cmp.Equal(x.AccessPath, y.AccessPath)
}
func DefaultLicenseComparer(x, y pkg.License) bool {
@ -161,7 +161,7 @@ func (p *CatalogTester) WithImageResolver(t *testing.T, fixtureName string) *Cat
func (p *CatalogTester) IgnoreLocationLayer() *CatalogTester {
p.locationComparer = func(x, y file.Location) bool {
return cmp.Equal(x.Coordinates.RealPath, y.Coordinates.RealPath) && cmp.Equal(x.VirtualPath, y.VirtualPath)
return cmp.Equal(x.Coordinates.RealPath, y.Coordinates.RealPath) && cmp.Equal(x.AccessPath, y.AccessPath)
}
// we need to update the license comparer to use the ignored location layer

View File

@ -87,7 +87,7 @@ func uniquePkgKey(groupID string, p *pkg.Package) string {
// and parse nested archives or ignore them.
func newJavaArchiveParser(reader file.LocationReadCloser, detectNested bool, cfg Config) (*archiveParser, func(), error) {
// fetch the last element of the virtual path
virtualElements := strings.Split(reader.AccessPath(), ":")
virtualElements := strings.Split(reader.Path(), ":")
currentFilepath := virtualElements[len(virtualElements)-1]
contentPath, archivePath, cleanupFn, err := saveArchiveToTmp(currentFilepath, reader)
@ -208,7 +208,7 @@ func (j *archiveParser) discoverMainPackage() (*pkg.Package, error) {
),
Type: j.fileInfo.pkgType(),
Metadata: pkg.JavaArchive{
VirtualPath: j.location.AccessPath(),
VirtualPath: j.location.Path(),
Manifest: manifest,
ArchiveDigests: digests,
},
@ -526,7 +526,7 @@ func discoverPkgsFromOpeners(location file.Location, openers map[string]intFile.
for pathWithinArchive, archiveOpener := range openers {
nestedPkgs, nestedRelationships, err := discoverPkgsFromOpener(location, pathWithinArchive, archiveOpener, cfg)
if err != nil {
log.WithFields("location", location.AccessPath()).Warnf("unable to discover java packages from opener: %+v", err)
log.WithFields("location", location.Path()).Warnf("unable to discover java packages from opener: %+v", err)
continue
}
@ -559,9 +559,9 @@ func discoverPkgsFromOpener(location file.Location, pathWithinArchive string, ar
}
}()
nestedPath := fmt.Sprintf("%s:%s", location.AccessPath(), pathWithinArchive)
nestedPath := fmt.Sprintf("%s:%s", location.Path(), pathWithinArchive)
nestedLocation := file.NewLocationFromCoordinates(location.Coordinates)
nestedLocation.VirtualPath = nestedPath
nestedLocation.AccessPath = nestedPath
gap := newGenericArchiveParserAdapter(cfg)
nestedPkgs, nestedRelationships, err := gap.parseJavaArchive(nil, nil, file.LocationReadCloser{
Location: nestedLocation,
@ -584,7 +584,7 @@ func pomPropertiesByParentPath(archivePath string, location file.Location, extra
for filePath, fileContents := range contentsOfMavenPropertiesFiles {
pomProperties, err := parsePomProperties(filePath, strings.NewReader(fileContents))
if err != nil {
log.WithFields("contents-path", filePath, "location", location.AccessPath()).Warnf("failed to parse pom.properties: %+v", err)
log.WithFields("contents-path", filePath, "location", location.Path()).Warnf("failed to parse pom.properties: %+v", err)
continue
}
@ -614,7 +614,7 @@ func pomProjectByParentPath(archivePath string, location file.Location, extractP
// TODO: when we support locations of paths within archives we should start passing the specific pom.xml location object instead of the top jar
pomProject, err := parsePomXMLProject(filePath, strings.NewReader(fileContents), location)
if err != nil {
log.WithFields("contents-path", filePath, "location", location.AccessPath()).Warnf("failed to parse pom.xml: %+v", err)
log.WithFields("contents-path", filePath, "location", location.Path()).Warnf("failed to parse pom.xml: %+v", err)
continue
}
@ -655,7 +655,7 @@ func newPackageFromMavenData(pomProperties pkg.JavaPomProperties, parsedPomProje
// https://github.com/anchore/syft/issues/1944
vPathSuffix += ":" + pomProperties.GroupID + ":" + pomProperties.ArtifactID
}
virtualPath := location.AccessPath() + vPathSuffix
virtualPath := location.Path() + vPathSuffix
var pkgPomProject *pkg.JavaPomProject
licenses := make([]pkg.License, 0)

View File

@ -57,7 +57,7 @@ func newGenericTarWrappedJavaArchiveParser(cfg Config) genericTarWrappedJavaArch
}
func (gtp genericTarWrappedJavaArchiveParser) parseTarWrappedJavaArchive(_ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
contentPath, archivePath, cleanupFn, err := saveArchiveToTmp(reader.AccessPath(), reader)
contentPath, archivePath, cleanupFn, err := saveArchiveToTmp(reader.Path(), reader)
// note: even on error, we should always run cleanup functions
defer cleanupFn()
if err != nil {

View File

@ -29,7 +29,7 @@ func newGenericZipWrappedJavaArchiveParser(cfg Config) genericZipWrappedJavaArch
}
func (gzp genericZipWrappedJavaArchiveParser) parseZipWrappedJavaArchive(_ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
contentPath, archivePath, cleanupFn, err := saveArchiveToTmp(reader.AccessPath(), reader)
contentPath, archivePath, cleanupFn, err := saveArchiveToTmp(reader.Path(), reader)
// note: even on error, we should always run cleanup functions
defer cleanupFn()
if err != nil {

View File

@ -64,7 +64,7 @@ func parsePackageJSON(_ file.Resolver, _ *generic.Environment, reader file.Locat
}
if !p.hasNameAndVersionValues() {
log.Debugf("encountered package.json file without a name and/or version field, ignoring (path=%q)", reader.AccessPath())
log.Debugf("encountered package.json file without a name and/or version field, ignoring (path=%q)", reader.Path())
return nil, nil, nil
}

View File

@ -47,7 +47,7 @@ type packageLockLicense []string
func parsePackageLock(resolver file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
// in the case we find package-lock.json files in the node_modules directories, skip those
// as the whole purpose of the lock file is for the specific dependencies of the root project
if pathContainsNodeModulesDirectory(reader.AccessPath()) {
if pathContainsNodeModulesDirectory(reader.Path()) {
return nil, nil, nil
}

View File

@ -46,7 +46,7 @@ const (
func parseYarnLock(resolver file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
// in the case we find yarn.lock files in the node_modules directories, skip those
// as the whole purpose of the lock file is for the specific dependencies of the project
if pathContainsNodeModulesDirectory(reader.AccessPath()) {
if pathContainsNodeModulesDirectory(reader.Path()) {
return nil, nil, nil
}

View File

@ -112,7 +112,7 @@ func fetchTopLevelPackages(resolver file.Resolver, metadataLocation file.Locatio
if err != nil {
return nil, nil, err
}
defer internal.CloseAndLogError(topLevelContents, topLevelLocation.VirtualPath)
defer internal.CloseAndLogError(topLevelContents, topLevelLocation.AccessPath)
scanner := bufio.NewScanner(topLevelContents)
for scanner.Scan() {
@ -162,7 +162,7 @@ func fetchDirectURLData(resolver file.Resolver, metadataLocation file.Location)
if err != nil {
return nil, nil, err
}
defer internal.CloseAndLogError(directURLContents, directURLLocation.VirtualPath)
defer internal.CloseAndLogError(directURLContents, directURLLocation.AccessPath)
buffer, err := io.ReadAll(directURLContents)
if err != nil {
@ -191,7 +191,7 @@ func assembleEggOrWheelMetadata(resolver file.Resolver, metadataLocation file.Lo
if err != nil {
return nil, nil, err
}
defer internal.CloseAndLogError(metadataContents, metadataLocation.VirtualPath)
defer internal.CloseAndLogError(metadataContents, metadataLocation.AccessPath)
pd, err := parseWheelOrEggMetadata(metadataLocation.RealPath, metadataContents)
if err != nil {

View File

@ -139,7 +139,7 @@ func TestLicenseSet_Add(t *testing.T) {
}
func defaultLocationComparer(x, y file.Location) bool {
return cmp.Equal(x.Coordinates, y.Coordinates) && cmp.Equal(x.VirtualPath, y.VirtualPath)
return cmp.Equal(x.Coordinates, y.Coordinates) && cmp.Equal(x.AccessPath, y.AccessPath)
}
func defaultLicenseComparer(x, y License) bool {

View File

@ -429,7 +429,7 @@ func licenseComparer(x, y License) bool {
}
func locationComparer(x, y file.Location) bool {
return cmp.Equal(x.Coordinates, y.Coordinates) && cmp.Equal(x.VirtualPath, y.VirtualPath)
return cmp.Equal(x.Coordinates, y.Coordinates) && cmp.Equal(x.AccessPath, y.AccessPath)
}
func TestIsValid(t *testing.T) {