mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
rename file.Location.VirtualPath to AccessPath (#2288)
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
parent
baa3dc74d3
commit
3f13d209a5
@ -63,7 +63,7 @@ func (i *Cataloger) catalogLocation(resolver file.Resolver, location file.Locati
|
|||||||
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)
|
||||||
|
|||||||
@ -81,7 +81,7 @@ func (i *Cataloger) catalogLocation(resolver file.Resolver, location file.Locati
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer internal.CloseAndLogError(contentReader, location.VirtualPath)
|
defer internal.CloseAndLogError(contentReader, location.AccessPath)
|
||||||
|
|
||||||
digests, err := intFile.NewDigestsFromFile(contentReader, i.hashes)
|
digests, err := intFile.NewDigestsFromFile(contentReader, i.hashes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -15,10 +15,10 @@ import (
|
|||||||
|
|
||||||
func Test_allRegularFiles(t *testing.T) {
|
func Test_allRegularFiles(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
setup func() file.Resolver
|
setup func() file.Resolver
|
||||||
wantRealPaths *strset.Set
|
wantRealPaths *strset.Set
|
||||||
wantVirtualPaths *strset.Set
|
wantAccessPaths *strset.Set
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "image",
|
name: "image",
|
||||||
@ -35,8 +35,8 @@ func Test_allRegularFiles(t *testing.T) {
|
|||||||
|
|
||||||
return r
|
return r
|
||||||
},
|
},
|
||||||
wantRealPaths: strset.New("/file-1.txt"),
|
wantRealPaths: strset.New("/file-1.txt"),
|
||||||
wantVirtualPaths: strset.New("/file-1.txt", "/symlink-1", "/hardlink-1"),
|
wantAccessPaths: strset.New("/file-1.txt", "/symlink-1", "/hardlink-1"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "directory",
|
name: "directory",
|
||||||
@ -47,8 +47,8 @@ func Test_allRegularFiles(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return r
|
return r
|
||||||
},
|
},
|
||||||
wantRealPaths: strset.New("file1.txt", "nested/file2.txt"),
|
wantRealPaths: strset.New("file1.txt", "nested/file2.txt"),
|
||||||
wantVirtualPaths: strset.New("file1.txt", "nested/file2.txt", "nested/linked-file1.txt"),
|
wantAccessPaths: strset.New("file1.txt", "nested/file2.txt", "nested/linked-file1.txt"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
@ -59,8 +59,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,10 +68,10 @@ func Test_allRegularFiles(t *testing.T) {
|
|||||||
realLocations.Remove("/hardlink-1")
|
realLocations.Remove("/hardlink-1")
|
||||||
virtualLocations.Remove("/hardlink-1")
|
virtualLocations.Remove("/hardlink-1")
|
||||||
tt.wantRealPaths.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.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 {
|
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(io.Discard, readCloser, start)
|
n, err := io.CopyN(io.Discard, readCloser, start)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -16,7 +16,7 @@ func catalogLocationByLine(resolver file.Resolver, location file.Location, patte
|
|||||||
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
|
||||||
@ -65,7 +65,7 @@ func searchForSecretsWithinLine(resolver file.Resolver, location file.Location,
|
|||||||
if secret != nil {
|
if secret != nil {
|
||||||
secrets = append(secrets, *secret)
|
secrets = append(secrets, *secret)
|
||||||
}
|
}
|
||||||
internal.CloseAndLogError(reader, location.VirtualPath)
|
internal.CloseAndLogError(reader, location.AccessPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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
|
// 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 {
|
type Location struct {
|
||||||
LocationData `cyclonedx:""`
|
LocationData `cyclonedx:""`
|
||||||
LocationMetadata `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"
|
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" json:"accessPath"` // The path to the file which may or may not have hardlinks / symlinks
|
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.
|
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 {
|
func (l LocationData) Reference() file.Reference {
|
||||||
@ -68,7 +68,7 @@ func NewLocation(realPath string) Location {
|
|||||||
Coordinates: Coordinates{
|
Coordinates: Coordinates{
|
||||||
RealPath: realPath,
|
RealPath: realPath,
|
||||||
},
|
},
|
||||||
VirtualPath: realPath,
|
AccessPath: realPath,
|
||||||
},
|
},
|
||||||
LocationMetadata: LocationMetadata{
|
LocationMetadata: LocationMetadata{
|
||||||
Annotations: map[string]string{},
|
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)
|
// 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{
|
||||||
LocationData: LocationData{
|
LocationData: LocationData{
|
||||||
Coordinates: Coordinates{
|
Coordinates: Coordinates{
|
||||||
RealPath: realPath,
|
RealPath: realPath,
|
||||||
},
|
},
|
||||||
VirtualPath: virtualPath,
|
AccessPath: accessPath,
|
||||||
},
|
},
|
||||||
LocationMetadata: LocationMetadata{
|
LocationMetadata: LocationMetadata{
|
||||||
Annotations: map[string]string{},
|
Annotations: map[string]string{},
|
||||||
@ -95,7 +95,7 @@ func NewLocationFromCoordinates(coordinates Coordinates) Location {
|
|||||||
return Location{
|
return Location{
|
||||||
LocationData: LocationData{
|
LocationData: LocationData{
|
||||||
Coordinates: coordinates,
|
Coordinates: coordinates,
|
||||||
VirtualPath: coordinates.RealPath,
|
AccessPath: coordinates.RealPath,
|
||||||
},
|
},
|
||||||
LocationMetadata: LocationMetadata{
|
LocationMetadata: LocationMetadata{
|
||||||
Annotations: map[string]string{},
|
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.
|
// 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{
|
return Location{
|
||||||
LocationData: LocationData{
|
LocationData: LocationData{
|
||||||
Coordinates: coordinates,
|
Coordinates: coordinates,
|
||||||
VirtualPath: virtualPath,
|
AccessPath: accessPath,
|
||||||
},
|
},
|
||||||
LocationMetadata: LocationMetadata{
|
LocationMetadata: LocationMetadata{
|
||||||
Annotations: map[string]string{},
|
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.
|
// 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)
|
layer := img.FileCatalog.Layer(ref)
|
||||||
return Location{
|
return Location{
|
||||||
LocationData: LocationData{
|
LocationData: LocationData{
|
||||||
@ -123,8 +123,8 @@ func NewLocationFromImage(virtualPath string, ref file.Reference, img *image.Ima
|
|||||||
RealPath: string(ref.RealPath),
|
RealPath: string(ref.RealPath),
|
||||||
FileSystemID: layer.Metadata.Digest,
|
FileSystemID: layer.Metadata.Digest,
|
||||||
},
|
},
|
||||||
VirtualPath: virtualPath,
|
AccessPath: accessPath,
|
||||||
ref: ref,
|
ref: ref,
|
||||||
},
|
},
|
||||||
LocationMetadata: LocationMetadata{
|
LocationMetadata: LocationMetadata{
|
||||||
Annotations: map[string]string{},
|
Annotations: map[string]string{},
|
||||||
@ -139,8 +139,8 @@ func NewLocationFromDirectory(responsePath string, ref file.Reference) Location
|
|||||||
Coordinates: Coordinates{
|
Coordinates: Coordinates{
|
||||||
RealPath: responsePath,
|
RealPath: responsePath,
|
||||||
},
|
},
|
||||||
VirtualPath: responsePath,
|
AccessPath: responsePath,
|
||||||
ref: ref,
|
ref: ref,
|
||||||
},
|
},
|
||||||
LocationMetadata: LocationMetadata{
|
LocationMetadata: LocationMetadata{
|
||||||
Annotations: map[string]string{},
|
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.
|
// 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{
|
return Location{
|
||||||
LocationData: LocationData{
|
LocationData: LocationData{
|
||||||
Coordinates: Coordinates{
|
Coordinates: Coordinates{
|
||||||
RealPath: responsePath,
|
RealPath: responsePath,
|
||||||
},
|
},
|
||||||
VirtualPath: virtualResponsePath,
|
AccessPath: responseAccessPath,
|
||||||
ref: ref,
|
ref: ref,
|
||||||
},
|
},
|
||||||
LocationMetadata: LocationMetadata{
|
LocationMetadata: LocationMetadata{
|
||||||
Annotations: map[string]string{},
|
Annotations: map[string]string{},
|
||||||
@ -164,9 +164,9 @@ func NewVirtualLocationFromDirectory(responsePath, virtualResponsePath string, r
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l Location) AccessPath() string {
|
func (l Location) Path() string {
|
||||||
if l.VirtualPath != "" {
|
if l.AccessPath != "" {
|
||||||
return l.VirtualPath
|
return l.AccessPath
|
||||||
}
|
}
|
||||||
return l.RealPath
|
return l.RealPath
|
||||||
}
|
}
|
||||||
@ -179,8 +179,8 @@ func (l Location) String() string {
|
|||||||
|
|
||||||
str += fmt.Sprintf("RealPath=%q", l.RealPath)
|
str += fmt.Sprintf("RealPath=%q", l.RealPath)
|
||||||
|
|
||||||
if l.VirtualPath != "" && l.VirtualPath != l.RealPath {
|
if l.AccessPath != "" && l.AccessPath != l.RealPath {
|
||||||
str += fmt.Sprintf(" VirtualPath=%q", l.VirtualPath)
|
str += fmt.Sprintf(" AccessPath=%q", l.AccessPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if l.FileSystemID != "" {
|
if l.FileSystemID != "" {
|
||||||
@ -191,6 +191,6 @@ func (l Location) String() string {
|
|||||||
|
|
||||||
func (l Location) Equals(other Location) bool {
|
func (l Location) Equals(other Location) bool {
|
||||||
return l.RealPath == other.RealPath &&
|
return l.RealPath == other.RealPath &&
|
||||||
l.VirtualPath == other.VirtualPath &&
|
l.AccessPath == other.AccessPath &&
|
||||||
l.FileSystemID == other.FileSystemID
|
l.FileSystemID == other.FileSystemID
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ func TestLocationSet(t *testing.T) {
|
|||||||
RealPath: "/etc/hosts",
|
RealPath: "/etc/hosts",
|
||||||
FileSystemID: "a",
|
FileSystemID: "a",
|
||||||
},
|
},
|
||||||
VirtualPath: "/var/etc/hosts",
|
AccessPath: "/var/etc/hosts",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ func TestLocationSet(t *testing.T) {
|
|||||||
RealPath: "/etc/hosts",
|
RealPath: "/etc/hosts",
|
||||||
FileSystemID: "a",
|
FileSystemID: "a",
|
||||||
},
|
},
|
||||||
VirtualPath: "/home/wagoodman/hosts",
|
AccessPath: "/home/wagoodman/hosts",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ func TestLocationSet(t *testing.T) {
|
|||||||
RealPath: "/bin",
|
RealPath: "/bin",
|
||||||
FileSystemID: "a",
|
FileSystemID: "a",
|
||||||
},
|
},
|
||||||
VirtualPath: "/usr/bin",
|
AccessPath: "/usr/bin",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ func TestLocationSet(t *testing.T) {
|
|||||||
RealPath: "/bin",
|
RealPath: "/bin",
|
||||||
FileSystemID: "b",
|
FileSystemID: "b",
|
||||||
},
|
},
|
||||||
VirtualPath: "/usr/bin",
|
AccessPath: "/usr/bin",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ func TestLocationSet_Hash(t *testing.T) {
|
|||||||
RealPath: "/etc/hosts",
|
RealPath: "/etc/hosts",
|
||||||
FileSystemID: "a",
|
FileSystemID: "a",
|
||||||
},
|
},
|
||||||
VirtualPath: "/var/etc/hosts",
|
AccessPath: "/var/etc/hosts",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ func TestLocationSet_Hash(t *testing.T) {
|
|||||||
RealPath: "/bin",
|
RealPath: "/bin",
|
||||||
FileSystemID: "a",
|
FileSystemID: "a",
|
||||||
},
|
},
|
||||||
VirtualPath: "/usr/bin",
|
AccessPath: "/usr/bin",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ func TestLocationSet_Hash(t *testing.T) {
|
|||||||
RealPath: "/bin",
|
RealPath: "/bin",
|
||||||
FileSystemID: "b",
|
FileSystemID: "b",
|
||||||
},
|
},
|
||||||
VirtualPath: "/usr/bin",
|
AccessPath: "/usr/bin",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,7 @@ func TestLocation_ID(t *testing.T) {
|
|||||||
l := Location{
|
l := Location{
|
||||||
LocationData: LocationData{
|
LocationData: LocationData{
|
||||||
Coordinates: test.coordinates,
|
Coordinates: test.coordinates,
|
||||||
VirtualPath: test.virtualPath,
|
AccessPath: test.virtualPath,
|
||||||
ref: test.ref,
|
ref: test.ref,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,10 +8,10 @@ func (l Locations) Len() int {
|
|||||||
|
|
||||||
func (l Locations) Less(i, j int) bool {
|
func (l Locations) Less(i, j int) bool {
|
||||||
if l[i].RealPath == l[j].RealPath {
|
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].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
|
return l[i].RealPath < l[j].RealPath
|
||||||
}
|
}
|
||||||
|
|||||||
@ -636,7 +636,7 @@ func Test_directPackageFiles(t *testing.T) {
|
|||||||
RealPath: "some-file",
|
RealPath: "some-file",
|
||||||
FileSystemID: "",
|
FileSystemID: "",
|
||||||
},
|
},
|
||||||
VirtualPath: "some-file",
|
AccessPath: "some-file",
|
||||||
},
|
},
|
||||||
LocationMetadata: file.LocationMetadata{
|
LocationMetadata: file.LocationMetadata{
|
||||||
Annotations: map[string]string{},
|
Annotations: map[string]string{},
|
||||||
|
|||||||
@ -111,8 +111,8 @@ func toPath(s source.Description, p pkg.Package) string {
|
|||||||
if len(locations) > 0 {
|
if len(locations) > 0 {
|
||||||
location := locations[0]
|
location := locations[0]
|
||||||
packagePath := location.RealPath
|
packagePath := location.RealPath
|
||||||
if location.VirtualPath != "" {
|
if location.AccessPath != "" {
|
||||||
packagePath = location.VirtualPath
|
packagePath = location.AccessPath
|
||||||
}
|
}
|
||||||
packagePath = strings.TrimPrefix(packagePath, "/")
|
packagePath = strings.TrimPrefix(packagePath, "/")
|
||||||
switch metadata := s.Metadata.(type) {
|
switch metadata := s.Metadata.(type) {
|
||||||
|
|||||||
@ -123,7 +123,7 @@ FileCopyrightText: NOASSERTION
|
|||||||
f = file.Location{
|
f = file.Location{
|
||||||
LocationData: file.LocationData{
|
LocationData: file.LocationData{
|
||||||
Coordinates: c,
|
Coordinates: c,
|
||||||
VirtualPath: "",
|
AccessPath: "",
|
||||||
},
|
},
|
||||||
LocationMetadata: file.LocationMetadata{},
|
LocationMetadata: file.LocationMetadata{},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -80,7 +80,7 @@ func Test_EncodeDecodeCycle(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, d := range deep.Equal(p, actualPackages[idx]) {
|
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
|
// location.Virtual path is not exposed in the json output
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@ -193,10 +193,10 @@ func (r *ContainerImageAllLayers) FileContentsByLocation(location file.Location)
|
|||||||
switch entry.Metadata.Type {
|
switch entry.Metadata.Type {
|
||||||
case stereoscopeFile.TypeSymLink, stereoscopeFile.TypeHardLink:
|
case stereoscopeFile.TypeSymLink, stereoscopeFile.TypeHardLink:
|
||||||
// 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
|
||||||
case stereoscopeFile.TypeDirectory:
|
case stereoscopeFile.TypeDirectory:
|
||||||
|
|||||||
@ -110,7 +110,7 @@ func (r Directory) FilesByPath(userPaths ...string) ([]file.Location, error) {
|
|||||||
continue
|
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)
|
ref, err := r.searchContext.SearchByPath(userStrPath, filetree.FollowBasenameLinks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Tracef("unable to evaluate symlink for path=%q : %+v", userPath, err)
|
log.Tracef("unable to evaluate symlink for path=%q : %+v", userPath, err)
|
||||||
|
|||||||
@ -65,13 +65,13 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
|
|||||||
t.Cleanup(cleanup)
|
t.Cleanup(cleanup)
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
cwd string
|
cwd string
|
||||||
root string
|
root string
|
||||||
base string
|
base string
|
||||||
input string
|
input string
|
||||||
expectedRealPath string
|
expectedRealPath string
|
||||||
expectedVirtualPath string // note: if empty it will be assumed to match the expectedRealPath
|
expectedAccessPath string // note: if empty it will be assumed to match the expectedRealPath
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "relative root, relative request, direct",
|
name: "relative root, relative request, direct",
|
||||||
@ -139,7 +139,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
|
|||||||
// outside the root.
|
// outside the root.
|
||||||
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
||||||
//expectedRealPath: "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",
|
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.
|
// outside the root.
|
||||||
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
||||||
//expectedRealPath: "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",
|
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.
|
// outside the root.
|
||||||
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
||||||
//expectedRealPath: "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",
|
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.
|
// outside the root.
|
||||||
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
||||||
//expectedRealPath: "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",
|
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.
|
// outside the root.
|
||||||
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
||||||
//expectedRealPath: "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",
|
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.
|
// outside the root.
|
||||||
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
||||||
//expectedRealPath: "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",
|
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.
|
// outside the root.
|
||||||
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
||||||
//expectedRealPath: "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",
|
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.
|
// outside the root.
|
||||||
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
||||||
//expectedRealPath: "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",
|
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.
|
// outside the root.
|
||||||
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
||||||
//expectedRealPath: "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",
|
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.
|
// outside the root.
|
||||||
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
|
||||||
//expectedRealPath: "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",
|
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...
|
// link to outside of root cases...
|
||||||
{
|
{
|
||||||
name: "relative root, relative request, abs indirect (outside of root)",
|
name: "relative root, relative request, abs indirect (outside of root)",
|
||||||
root: filepath.Join(relative, "path"),
|
root: filepath.Join(relative, "path"),
|
||||||
input: "to/the/abs-outside.txt",
|
input: "to/the/abs-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
expectedAccessPath: "to/the/abs-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, relative request, abs indirect (outside of root)",
|
name: "abs root, relative request, abs indirect (outside of root)",
|
||||||
root: filepath.Join(absolute, "path"),
|
root: filepath.Join(absolute, "path"),
|
||||||
input: "to/the/abs-outside.txt",
|
input: "to/the/abs-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
expectedAccessPath: "to/the/abs-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relative root, abs request, abs indirect (outside of root)",
|
name: "relative root, abs request, abs indirect (outside of root)",
|
||||||
root: filepath.Join(relative, "path"),
|
root: filepath.Join(relative, "path"),
|
||||||
input: "/to/the/abs-outside.txt",
|
input: "/to/the/abs-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
expectedAccessPath: "to/the/abs-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, abs request, abs indirect (outside of root)",
|
name: "abs root, abs request, abs indirect (outside of root)",
|
||||||
root: filepath.Join(absolute, "path"),
|
root: filepath.Join(absolute, "path"),
|
||||||
input: "/to/the/abs-outside.txt",
|
input: "/to/the/abs-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
expectedAccessPath: "to/the/abs-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relative root, relative request, relative indirect (outside of root)",
|
name: "relative root, relative request, relative indirect (outside of root)",
|
||||||
root: filepath.Join(relative, "path"),
|
root: filepath.Join(relative, "path"),
|
||||||
input: "to/the/rel-outside.txt",
|
input: "to/the/rel-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, relative request, relative indirect (outside of root)",
|
name: "abs root, relative request, relative indirect (outside of root)",
|
||||||
root: filepath.Join(absolute, "path"),
|
root: filepath.Join(absolute, "path"),
|
||||||
input: "to/the/rel-outside.txt",
|
input: "to/the/rel-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relative root, abs request, relative indirect (outside of root)",
|
name: "relative root, abs request, relative indirect (outside of root)",
|
||||||
root: filepath.Join(relative, "path"),
|
root: filepath.Join(relative, "path"),
|
||||||
input: "/to/the/rel-outside.txt",
|
input: "/to/the/rel-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, abs request, relative indirect (outside of root)",
|
name: "abs root, abs request, relative indirect (outside of root)",
|
||||||
root: filepath.Join(absolute, "path"),
|
root: filepath.Join(absolute, "path"),
|
||||||
input: "/to/the/rel-outside.txt",
|
input: "/to/the/rel-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
// link to outside of root cases... cwd within symlink root
|
// link to outside of root cases... cwd within symlink root
|
||||||
{
|
{
|
||||||
name: "relative root, relative request, abs indirect (outside of root), cwd within symlink root",
|
name: "relative root, relative request, abs indirect (outside of root), cwd within symlink root",
|
||||||
cwd: relativeViaLink,
|
cwd: relativeViaLink,
|
||||||
root: "path",
|
root: "path",
|
||||||
input: "to/the/abs-outside.txt",
|
input: "to/the/abs-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
expectedAccessPath: "to/the/abs-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, relative request, abs indirect (outside of root), cwd within symlink root",
|
name: "abs root, relative request, abs indirect (outside of root), cwd within symlink root",
|
||||||
cwd: relativeViaLink,
|
cwd: relativeViaLink,
|
||||||
root: filepath.Join(absolute, "path"),
|
root: filepath.Join(absolute, "path"),
|
||||||
input: "to/the/abs-outside.txt",
|
input: "to/the/abs-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
expectedAccessPath: "to/the/abs-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relative root, abs request, abs indirect (outside of root), cwd within symlink root",
|
name: "relative root, abs request, abs indirect (outside of root), cwd within symlink root",
|
||||||
cwd: relativeViaLink,
|
cwd: relativeViaLink,
|
||||||
root: "path",
|
root: "path",
|
||||||
input: "/to/the/abs-outside.txt",
|
input: "/to/the/abs-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
expectedAccessPath: "to/the/abs-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, abs request, abs indirect (outside of root), cwd within symlink root",
|
name: "abs root, abs request, abs indirect (outside of root), cwd within symlink root",
|
||||||
cwd: relativeViaLink,
|
cwd: relativeViaLink,
|
||||||
root: filepath.Join(absolute, "path"),
|
root: filepath.Join(absolute, "path"),
|
||||||
input: "/to/the/abs-outside.txt",
|
input: "/to/the/abs-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
expectedAccessPath: "to/the/abs-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relative root, relative request, relative indirect (outside of root), cwd within symlink root",
|
name: "relative root, relative request, relative indirect (outside of root), cwd within symlink root",
|
||||||
cwd: relativeViaLink,
|
cwd: relativeViaLink,
|
||||||
root: "path",
|
root: "path",
|
||||||
input: "to/the/rel-outside.txt",
|
input: "to/the/rel-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, relative request, relative indirect (outside of root), cwd within symlink root",
|
name: "abs root, relative request, relative indirect (outside of root), cwd within symlink root",
|
||||||
cwd: relativeViaLink,
|
cwd: relativeViaLink,
|
||||||
root: filepath.Join(absolute, "path"),
|
root: filepath.Join(absolute, "path"),
|
||||||
input: "to/the/rel-outside.txt",
|
input: "to/the/rel-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relative root, abs request, relative indirect (outside of root), cwd within symlink root",
|
name: "relative root, abs request, relative indirect (outside of root), cwd within symlink root",
|
||||||
cwd: relativeViaLink,
|
cwd: relativeViaLink,
|
||||||
root: "path",
|
root: "path",
|
||||||
input: "/to/the/rel-outside.txt",
|
input: "/to/the/rel-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, abs request, relative indirect (outside of root), cwd within symlink root",
|
name: "abs root, abs request, relative indirect (outside of root), cwd within symlink root",
|
||||||
cwd: relativeViaLink,
|
cwd: relativeViaLink,
|
||||||
root: filepath.Join(absolute, "path"),
|
root: filepath.Join(absolute, "path"),
|
||||||
input: "/to/the/rel-outside.txt",
|
input: "/to/the/rel-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relative root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
|
name: "relative root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
|
||||||
cwd: relativeViaDoubleLink,
|
cwd: relativeViaDoubleLink,
|
||||||
root: "path",
|
root: "path",
|
||||||
input: "to/the/rel-outside.txt",
|
input: "to/the/rel-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
|
name: "abs root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
|
||||||
cwd: relativeViaDoubleLink,
|
cwd: relativeViaDoubleLink,
|
||||||
root: filepath.Join(absolute, "path"),
|
root: filepath.Join(absolute, "path"),
|
||||||
input: "to/the/rel-outside.txt",
|
input: "to/the/rel-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relative root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
|
name: "relative root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
|
||||||
cwd: relativeViaDoubleLink,
|
cwd: relativeViaDoubleLink,
|
||||||
root: "path",
|
root: "path",
|
||||||
input: "/to/the/rel-outside.txt",
|
input: "/to/the/rel-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
|
name: "abs root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
|
||||||
cwd: relativeViaDoubleLink,
|
cwd: relativeViaDoubleLink,
|
||||||
root: filepath.Join(absolute, "path"),
|
root: filepath.Join(absolute, "path"),
|
||||||
input: "/to/the/rel-outside.txt",
|
input: "/to/the/rel-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
if c.expectedVirtualPath == "" {
|
if c.expectedAccessPath == "" {
|
||||||
c.expectedVirtualPath = c.expectedRealPath
|
c.expectedAccessPath = c.expectedRealPath
|
||||||
}
|
}
|
||||||
|
|
||||||
// we need to mimic a shell, otherwise we won't get a path within a symlink
|
// 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)
|
require.Len(t, refs, 1)
|
||||||
assert.Equal(t, c.expectedRealPath, refs[0].RealPath, "real path different")
|
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.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_*")
|
||||||
@ -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
|
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
|
// returned locations can be in any order
|
||||||
expectedVirtualPaths := []string{
|
expectedAccessPaths := []string{
|
||||||
"link_to_link_to_new_readme",
|
"link_to_link_to_new_readme",
|
||||||
//"link_to_new_readme", // we filter out this one because the first symlink resolves to the same file
|
//"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()
|
actualRealPaths := strset.New()
|
||||||
actualVirtualPaths := strset.New()
|
actualAccessPaths := strset.New()
|
||||||
for _, a := range locations {
|
for _, a := range locations {
|
||||||
actualVirtualPaths.Add(a.VirtualPath)
|
actualAccessPaths.Add(a.AccessPath)
|
||||||
actualRealPaths.Add(a.RealPath)
|
actualRealPaths.Add(a.RealPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.ElementsMatch(t, expectedVirtualPaths, actualVirtualPaths.List())
|
assert.ElementsMatch(t, expectedAccessPaths, actualAccessPaths.List())
|
||||||
assert.ElementsMatch(t, expectedRealPaths, actualRealPaths.List())
|
assert.ElementsMatch(t, expectedRealPaths, actualRealPaths.List())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -83,7 +83,7 @@ func (r *excluding) 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) {
|
||||||
|
|||||||
@ -165,8 +165,8 @@ nextPath:
|
|||||||
for i := range out {
|
for i := range out {
|
||||||
existing := &out[i]
|
existing := &out[i]
|
||||||
if existing.RealPath == l.RealPath {
|
if existing.RealPath == l.RealPath {
|
||||||
if l.VirtualPath == "" {
|
if l.AccessPath == "" {
|
||||||
existing.VirtualPath = ""
|
existing.AccessPath = ""
|
||||||
}
|
}
|
||||||
continue nextPath
|
continue nextPath
|
||||||
}
|
}
|
||||||
|
|||||||
@ -90,13 +90,13 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
|
|||||||
t.Cleanup(cleanup)
|
t.Cleanup(cleanup)
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
cwd string
|
cwd string
|
||||||
root string
|
root string
|
||||||
base string
|
base string
|
||||||
input string
|
input string
|
||||||
expectedRealPath string
|
expectedRealPath string
|
||||||
expectedVirtualPath string // if empty, the virtual path should be the same as the real path
|
expectedAccessPath string // if empty, the virtual path should be the same as the real path
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "relative root, relative request, direct",
|
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...
|
// link to outside of root cases...
|
||||||
{
|
{
|
||||||
name: "relative root, relative request, abs indirect (outside of root)",
|
name: "relative root, relative request, abs indirect (outside of root)",
|
||||||
root: filepath.Join(relative, "path"),
|
root: filepath.Join(relative, "path"),
|
||||||
input: "to/the/abs-outside.txt",
|
input: "to/the/abs-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
expectedAccessPath: "to/the/abs-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, relative request, abs indirect (outside of root)",
|
name: "abs root, relative request, abs indirect (outside of root)",
|
||||||
root: filepath.Join(absolute, "path"),
|
root: filepath.Join(absolute, "path"),
|
||||||
input: "to/the/abs-outside.txt",
|
input: "to/the/abs-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
expectedAccessPath: "to/the/abs-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relative root, abs request, abs indirect (outside of root)",
|
name: "relative root, abs request, abs indirect (outside of root)",
|
||||||
root: filepath.Join(relative, "path"),
|
root: filepath.Join(relative, "path"),
|
||||||
input: "/to/the/abs-outside.txt",
|
input: "/to/the/abs-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
expectedAccessPath: "to/the/abs-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, abs request, abs indirect (outside of root)",
|
name: "abs root, abs request, abs indirect (outside of root)",
|
||||||
root: filepath.Join(absolute, "path"),
|
root: filepath.Join(absolute, "path"),
|
||||||
input: "/to/the/abs-outside.txt",
|
input: "/to/the/abs-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
expectedAccessPath: "to/the/abs-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relative root, relative request, relative indirect (outside of root)",
|
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",
|
input: "to/the/rel-outside.txt",
|
||||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
// TODO: the real path is not correct
|
// TODO: the real path is not correct
|
||||||
expectedRealPath: "../somewhere/outside.txt",
|
expectedRealPath: "../somewhere/outside.txt",
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, relative request, relative indirect (outside of root)",
|
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",
|
input: "to/the/rel-outside.txt",
|
||||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
// TODO: the real path is not correct
|
// TODO: the real path is not correct
|
||||||
expectedRealPath: "../somewhere/outside.txt",
|
expectedRealPath: "../somewhere/outside.txt",
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relative root, abs request, relative indirect (outside of root)",
|
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",
|
input: "/to/the/rel-outside.txt",
|
||||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
// TODO: the real path is not correct
|
// TODO: the real path is not correct
|
||||||
expectedRealPath: "../somewhere/outside.txt",
|
expectedRealPath: "../somewhere/outside.txt",
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, abs request, relative indirect (outside of root)",
|
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",
|
input: "/to/the/rel-outside.txt",
|
||||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
// TODO: the real path is not correct
|
// TODO: the real path is not correct
|
||||||
expectedRealPath: "../somewhere/outside.txt",
|
expectedRealPath: "../somewhere/outside.txt",
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
// link to outside of root cases... cwd within symlink root
|
// link to outside of root cases... cwd within symlink root
|
||||||
{
|
{
|
||||||
name: "relative root, relative request, abs indirect (outside of root), cwd within symlink root",
|
name: "relative root, relative request, abs indirect (outside of root), cwd within symlink root",
|
||||||
cwd: relativeViaLink,
|
cwd: relativeViaLink,
|
||||||
root: "path",
|
root: "path",
|
||||||
input: "to/the/abs-outside.txt",
|
input: "to/the/abs-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
expectedAccessPath: "to/the/abs-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, relative request, abs indirect (outside of root), cwd within symlink root",
|
name: "abs root, relative request, abs indirect (outside of root), cwd within symlink root",
|
||||||
cwd: relativeViaLink,
|
cwd: relativeViaLink,
|
||||||
root: filepath.Join(absolute, "path"),
|
root: filepath.Join(absolute, "path"),
|
||||||
input: "to/the/abs-outside.txt",
|
input: "to/the/abs-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
expectedAccessPath: "to/the/abs-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relative root, abs request, abs indirect (outside of root), cwd within symlink root",
|
name: "relative root, abs request, abs indirect (outside of root), cwd within symlink root",
|
||||||
cwd: relativeViaLink,
|
cwd: relativeViaLink,
|
||||||
root: "path",
|
root: "path",
|
||||||
input: "/to/the/abs-outside.txt",
|
input: "/to/the/abs-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
expectedAccessPath: "to/the/abs-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, abs request, abs indirect (outside of root), cwd within symlink root",
|
name: "abs root, abs request, abs indirect (outside of root), cwd within symlink root",
|
||||||
cwd: relativeViaLink,
|
cwd: relativeViaLink,
|
||||||
root: filepath.Join(absolute, "path"),
|
root: filepath.Join(absolute, "path"),
|
||||||
input: "/to/the/abs-outside.txt",
|
input: "/to/the/abs-outside.txt",
|
||||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
expectedAccessPath: "to/the/abs-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relative root, relative request, relative indirect (outside of root), cwd within symlink root",
|
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",
|
input: "to/the/rel-outside.txt",
|
||||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
// TODO: the real path is not correct
|
// TODO: the real path is not correct
|
||||||
expectedRealPath: "../somewhere/outside.txt",
|
expectedRealPath: "../somewhere/outside.txt",
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, relative request, relative indirect (outside of root), cwd within symlink root",
|
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",
|
input: "to/the/rel-outside.txt",
|
||||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
// TODO: the real path is not correct
|
// TODO: the real path is not correct
|
||||||
expectedRealPath: "../somewhere/outside.txt",
|
expectedRealPath: "../somewhere/outside.txt",
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relative root, abs request, relative indirect (outside of root), cwd within symlink root",
|
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",
|
input: "/to/the/rel-outside.txt",
|
||||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
// TODO: the real path is not correct
|
// TODO: the real path is not correct
|
||||||
expectedRealPath: "../somewhere/outside.txt",
|
expectedRealPath: "../somewhere/outside.txt",
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, abs request, relative indirect (outside of root), cwd within symlink root",
|
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",
|
input: "/to/the/rel-outside.txt",
|
||||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
// TODO: the real path is not correct
|
// TODO: the real path is not correct
|
||||||
expectedRealPath: "../somewhere/outside.txt",
|
expectedRealPath: "../somewhere/outside.txt",
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relative root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
|
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",
|
input: "to/the/rel-outside.txt",
|
||||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
// TODO: the real path is not correct
|
// TODO: the real path is not correct
|
||||||
expectedRealPath: "../somewhere/outside.txt",
|
expectedRealPath: "../somewhere/outside.txt",
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
|
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",
|
input: "to/the/rel-outside.txt",
|
||||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
// TODO: the real path is not correct
|
// TODO: the real path is not correct
|
||||||
expectedRealPath: "../somewhere/outside.txt",
|
expectedRealPath: "../somewhere/outside.txt",
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relative root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
|
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",
|
input: "/to/the/rel-outside.txt",
|
||||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
// TODO: the real path is not correct
|
// TODO: the real path is not correct
|
||||||
expectedRealPath: "../somewhere/outside.txt",
|
expectedRealPath: "../somewhere/outside.txt",
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "abs root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
|
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",
|
input: "/to/the/rel-outside.txt",
|
||||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||||
// TODO: the real path is not correct
|
// TODO: the real path is not correct
|
||||||
expectedRealPath: "../somewhere/outside.txt",
|
expectedRealPath: "../somewhere/outside.txt",
|
||||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
expectedAccessPath: "to/the/rel-outside.txt",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
if c.expectedVirtualPath == "" {
|
if c.expectedAccessPath == "" {
|
||||||
c.expectedVirtualPath = c.expectedRealPath
|
c.expectedAccessPath = c.expectedRealPath
|
||||||
}
|
}
|
||||||
|
|
||||||
// we need to mimic a shell, otherwise we won't get a path within a symlink
|
// 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)
|
require.Len(t, refs, 1)
|
||||||
assert.Equal(t, c.expectedRealPath, refs[0].RealPath, "real path different")
|
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.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_*")
|
||||||
@ -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
|
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
|
// returned locations can be in any order
|
||||||
expectedVirtualPaths := []string{
|
expectedAccessPaths := []string{
|
||||||
"link_to_link_to_new_readme",
|
"link_to_link_to_new_readme",
|
||||||
//"link_to_new_readme", // we filter out this one because the first symlink resolves to the same file
|
//"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()
|
actualRealPaths := strset.New()
|
||||||
actualVirtualPaths := strset.New()
|
actualAccessPaths := strset.New()
|
||||||
for _, a := range locations {
|
for _, a := range locations {
|
||||||
actualVirtualPaths.Add(a.VirtualPath)
|
actualAccessPaths.Add(a.AccessPath)
|
||||||
actualRealPaths.Add(a.RealPath)
|
actualRealPaths.Add(a.RealPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.ElementsMatch(t, expectedVirtualPaths, actualVirtualPaths.List())
|
assert.ElementsMatch(t, expectedAccessPaths, actualAccessPaths.List())
|
||||||
assert.ElementsMatch(t, expectedRealPaths, actualRealPaths.List())
|
assert.ElementsMatch(t, expectedRealPaths, actualRealPaths.List())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -71,7 +71,7 @@ func IdentifyRelease(resolver file.Resolver) *Release {
|
|||||||
}
|
}
|
||||||
|
|
||||||
content, err := io.ReadAll(contentReader)
|
content, err := io.ReadAll(contentReader)
|
||||||
internal.CloseAndLogError(contentReader, location.VirtualPath)
|
internal.CloseAndLogError(contentReader, location.AccessPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.WithFields("error", err, "path", location.RealPath).Trace("unable to read contents")
|
logger.WithFields("error", err, "path", location.RealPath).Trace("unable to read contents")
|
||||||
continue
|
continue
|
||||||
|
|||||||
@ -130,9 +130,9 @@ func (c *Collection) addPathsToIndex(p Package) {
|
|||||||
c.addPathToIndex(p.id, l.RealPath)
|
c.addPathToIndex(p.id, l.RealPath)
|
||||||
observedPaths.Add(l.RealPath)
|
observedPaths.Add(l.RealPath)
|
||||||
}
|
}
|
||||||
if l.VirtualPath != "" && l.RealPath != l.VirtualPath && !observedPaths.Has(l.VirtualPath) {
|
if l.AccessPath != "" && l.RealPath != l.AccessPath && !observedPaths.Has(l.AccessPath) {
|
||||||
c.addPathToIndex(p.id, l.VirtualPath)
|
c.addPathToIndex(p.id, l.AccessPath)
|
||||||
observedPaths.Add(l.VirtualPath)
|
observedPaths.Add(l.AccessPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,9 +179,9 @@ func (c *Collection) deletePathsFromIndex(p Package) {
|
|||||||
c.deletePathFromIndex(p.id, l.RealPath)
|
c.deletePathFromIndex(p.id, l.RealPath)
|
||||||
observedPaths.Add(l.RealPath)
|
observedPaths.Add(l.RealPath)
|
||||||
}
|
}
|
||||||
if l.VirtualPath != "" && l.RealPath != l.VirtualPath && !observedPaths.Has(l.VirtualPath) {
|
if l.AccessPath != "" && l.RealPath != l.AccessPath && !observedPaths.Has(l.AccessPath) {
|
||||||
c.deletePathFromIndex(p.id, l.VirtualPath)
|
c.deletePathFromIndex(p.id, l.AccessPath)
|
||||||
observedPaths.Add(l.VirtualPath)
|
observedPaths.Add(l.AccessPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -833,7 +833,7 @@ func assertPackagesAreEqual(t *testing.T, expected pkg.Package, p pkg.Package) {
|
|||||||
matches = false
|
matches = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if m1.Location.VirtualPath != "" && m1.Location.VirtualPath != m2.Location.VirtualPath {
|
if m1.Location.AccessPath != "" && m1.Location.AccessPath != m2.Location.AccessPath {
|
||||||
matches = false
|
matches = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import (
|
|||||||
var _ generic.Parser = parseConaninfo
|
var _ generic.Parser = parseConaninfo
|
||||||
|
|
||||||
func parseConanMetadataFromFilePath(path string) (pkg.ConaninfoEntry, error) {
|
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.:
|
// 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
|
// $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`)
|
re := regexp.MustCompile(`.*[/\\](?P<name>[^/\\]+)[/\\](?P<version>[^/\\]+)[/\\](?P<user>[^/\\]+)[/\\](?P<channel>[^/\\]+)[/\\]package[/\\](?P<id>[^/\\]+)[/\\]conaninfo\.txt`)
|
||||||
|
|||||||
@ -96,7 +96,7 @@ func addLicenses(resolver file.Resolver, dbLocation file.Location, p *pkg.Packag
|
|||||||
copyrightReader, copyrightLocation := fetchCopyrightContents(resolver, dbLocation, metadata)
|
copyrightReader, copyrightLocation := fetchCopyrightContents(resolver, dbLocation, metadata)
|
||||||
|
|
||||||
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
|
||||||
licenseStrs := parseLicensesFromCopyright(copyrightReader)
|
licenseStrs := parseLicensesFromCopyright(copyrightReader)
|
||||||
for _, licenseStr := range licenseStrs {
|
for _, licenseStr := range licenseStrs {
|
||||||
@ -147,7 +147,7 @@ func getAdditionalFileListing(resolver file.Resolver, dbLocation file.Location,
|
|||||||
md5Reader, md5Location := fetchMd5Contents(resolver, dbLocation, m)
|
md5Reader, md5Location := fetchMd5Contents(resolver, dbLocation, m)
|
||||||
|
|
||||||
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)...)
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ func getAdditionalFileListing(resolver file.Resolver, dbLocation file.Location,
|
|||||||
conffilesReader, conffilesLocation := fetchConffileContents(resolver, dbLocation, m)
|
conffilesReader, conffilesLocation := fetchConffileContents(resolver, dbLocation, m)
|
||||||
|
|
||||||
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)...)
|
||||||
|
|
||||||
|
|||||||
@ -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)
|
return nil, nil, fmt.Errorf("failed to parse deps.json file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rootName := getDepsJSONFilePrefix(reader.AccessPath())
|
rootName := getDepsJSONFilePrefix(reader.Path())
|
||||||
if rootName == "" {
|
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
|
var rootPkg *pkg.Package
|
||||||
for nameVersion, lib := range depsDoc.Libraries {
|
for nameVersion, lib := range depsDoc.Libraries {
|
||||||
@ -65,7 +65,7 @@ func parseDotnetDeps(_ file.Resolver, _ *generic.Environment, reader file.Locati
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if rootPkg == nil {
|
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)
|
pkgs = append(pkgs, *rootPkg)
|
||||||
pkgMap[createNameAndVersion(rootPkg.Name, rootPkg.Version)] = *rootPkg
|
pkgMap[createNameAndVersion(rootPkg.Name, rootPkg.Version)] = *rootPkg
|
||||||
|
|||||||
@ -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))
|
discoveredPackages, discoveredRelationships, err := parser(resolver, &env, file.NewLocationReadCloser(location, contentReader))
|
||||||
internal.CloseAndLogError(contentReader, location.VirtualPath)
|
internal.CloseAndLogError(contentReader, location.AccessPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.WithFields("location", location.RealPath, "error", err).Warnf("cataloger failed")
|
logger.WithFields("location", location.RealPath, "error", err).Warnf("cataloger failed")
|
||||||
continue
|
continue
|
||||||
|
|||||||
@ -16,7 +16,7 @@ import (
|
|||||||
func Test_Cataloger(t *testing.T) {
|
func Test_Cataloger(t *testing.T) {
|
||||||
allParsedPaths := make(map[string]bool)
|
allParsedPaths := make(map[string]bool)
|
||||||
parser := func(resolver file.Resolver, env *Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
|
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)
|
contents, err := io.ReadAll(reader)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|||||||
@ -61,7 +61,7 @@ func NewCatalogTester() *CatalogTester {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func DefaultLocationComparer(x, y file.Location) bool {
|
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 {
|
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 {
|
func (p *CatalogTester) IgnoreLocationLayer() *CatalogTester {
|
||||||
p.locationComparer = func(x, y file.Location) bool {
|
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
|
// we need to update the license comparer to use the ignored location layer
|
||||||
|
|||||||
@ -87,7 +87,7 @@ func uniquePkgKey(groupID string, p *pkg.Package) string {
|
|||||||
// and parse nested archives or ignore them.
|
// and parse nested archives or ignore them.
|
||||||
func newJavaArchiveParser(reader file.LocationReadCloser, detectNested bool, cfg Config) (*archiveParser, func(), error) {
|
func newJavaArchiveParser(reader file.LocationReadCloser, detectNested bool, cfg Config) (*archiveParser, func(), error) {
|
||||||
// fetch the last element of the virtual path
|
// fetch the last element of the virtual path
|
||||||
virtualElements := strings.Split(reader.AccessPath(), ":")
|
virtualElements := strings.Split(reader.Path(), ":")
|
||||||
currentFilepath := virtualElements[len(virtualElements)-1]
|
currentFilepath := virtualElements[len(virtualElements)-1]
|
||||||
|
|
||||||
contentPath, archivePath, cleanupFn, err := saveArchiveToTmp(currentFilepath, reader)
|
contentPath, archivePath, cleanupFn, err := saveArchiveToTmp(currentFilepath, reader)
|
||||||
@ -208,7 +208,7 @@ func (j *archiveParser) discoverMainPackage() (*pkg.Package, error) {
|
|||||||
),
|
),
|
||||||
Type: j.fileInfo.pkgType(),
|
Type: j.fileInfo.pkgType(),
|
||||||
Metadata: pkg.JavaArchive{
|
Metadata: pkg.JavaArchive{
|
||||||
VirtualPath: j.location.AccessPath(),
|
VirtualPath: j.location.Path(),
|
||||||
Manifest: manifest,
|
Manifest: manifest,
|
||||||
ArchiveDigests: digests,
|
ArchiveDigests: digests,
|
||||||
},
|
},
|
||||||
@ -526,7 +526,7 @@ func discoverPkgsFromOpeners(location file.Location, openers map[string]intFile.
|
|||||||
for pathWithinArchive, archiveOpener := range openers {
|
for pathWithinArchive, archiveOpener := range openers {
|
||||||
nestedPkgs, nestedRelationships, err := discoverPkgsFromOpener(location, pathWithinArchive, archiveOpener, cfg)
|
nestedPkgs, nestedRelationships, err := discoverPkgsFromOpener(location, pathWithinArchive, archiveOpener, cfg)
|
||||||
if err != nil {
|
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
|
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 := file.NewLocationFromCoordinates(location.Coordinates)
|
||||||
nestedLocation.VirtualPath = nestedPath
|
nestedLocation.AccessPath = nestedPath
|
||||||
gap := newGenericArchiveParserAdapter(cfg)
|
gap := newGenericArchiveParserAdapter(cfg)
|
||||||
nestedPkgs, nestedRelationships, err := gap.parseJavaArchive(nil, nil, file.LocationReadCloser{
|
nestedPkgs, nestedRelationships, err := gap.parseJavaArchive(nil, nil, file.LocationReadCloser{
|
||||||
Location: nestedLocation,
|
Location: nestedLocation,
|
||||||
@ -584,7 +584,7 @@ func pomPropertiesByParentPath(archivePath string, location file.Location, extra
|
|||||||
for filePath, fileContents := range contentsOfMavenPropertiesFiles {
|
for filePath, fileContents := range contentsOfMavenPropertiesFiles {
|
||||||
pomProperties, err := parsePomProperties(filePath, strings.NewReader(fileContents))
|
pomProperties, err := parsePomProperties(filePath, strings.NewReader(fileContents))
|
||||||
if err != nil {
|
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
|
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
|
// 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)
|
pomProject, err := parsePomXMLProject(filePath, strings.NewReader(fileContents), location)
|
||||||
if err != nil {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -655,7 +655,7 @@ func newPackageFromMavenData(pomProperties pkg.JavaPomProperties, parsedPomProje
|
|||||||
// https://github.com/anchore/syft/issues/1944
|
// https://github.com/anchore/syft/issues/1944
|
||||||
vPathSuffix += ":" + pomProperties.GroupID + ":" + pomProperties.ArtifactID
|
vPathSuffix += ":" + pomProperties.GroupID + ":" + pomProperties.ArtifactID
|
||||||
}
|
}
|
||||||
virtualPath := location.AccessPath() + vPathSuffix
|
virtualPath := location.Path() + vPathSuffix
|
||||||
|
|
||||||
var pkgPomProject *pkg.JavaPomProject
|
var pkgPomProject *pkg.JavaPomProject
|
||||||
licenses := make([]pkg.License, 0)
|
licenses := make([]pkg.License, 0)
|
||||||
|
|||||||
@ -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) {
|
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
|
// note: even on error, we should always run cleanup functions
|
||||||
defer cleanupFn()
|
defer cleanupFn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -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) {
|
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
|
// note: even on error, we should always run cleanup functions
|
||||||
defer cleanupFn()
|
defer cleanupFn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -64,7 +64,7 @@ func parsePackageJSON(_ file.Resolver, _ *generic.Environment, reader file.Locat
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !p.hasNameAndVersionValues() {
|
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
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -47,7 +47,7 @@ type packageLockLicense []string
|
|||||||
func parsePackageLock(resolver file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
|
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
|
// 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
|
// 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
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -46,7 +46,7 @@ const (
|
|||||||
func parseYarnLock(resolver file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
|
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
|
// 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
|
// 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
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -112,7 +112,7 @@ func fetchTopLevelPackages(resolver file.Resolver, metadataLocation file.Locatio
|
|||||||
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() {
|
||||||
@ -162,7 +162,7 @@ func fetchDirectURLData(resolver file.Resolver, metadataLocation file.Location)
|
|||||||
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 := io.ReadAll(directURLContents)
|
buffer, err := io.ReadAll(directURLContents)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -191,7 +191,7 @@ func assembleEggOrWheelMetadata(resolver file.Resolver, metadataLocation file.Lo
|
|||||||
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)
|
||||||
|
|
||||||
pd, err := parseWheelOrEggMetadata(metadataLocation.RealPath, metadataContents)
|
pd, err := parseWheelOrEggMetadata(metadataLocation.RealPath, metadataContents)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -139,7 +139,7 @@ func TestLicenseSet_Add(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func defaultLocationComparer(x, y file.Location) bool {
|
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 {
|
func defaultLicenseComparer(x, y License) bool {
|
||||||
|
|||||||
@ -429,7 +429,7 @@ func licenseComparer(x, y License) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func locationComparer(x, y file.Location) 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) {
|
func TestIsValid(t *testing.T) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user