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

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
Alex Goodman
2023-11-09 11:30:08 -06:00
committed by GitHub
parent baa3dc74d3
commit 3f13d209a5
37 changed files with 320 additions and 320 deletions
@@ -193,10 +193,10 @@ func (r *ContainerImageAllLayers) FileContentsByLocation(location file.Location)
switch entry.Metadata.Type {
case stereoscopeFile.TypeSymLink, stereoscopeFile.TypeHardLink:
// the location we are searching may be a symlink, we should always work with the resolved file
newLocation := r.RelativeFileByPath(location, location.VirtualPath)
newLocation := r.RelativeFileByPath(location, location.AccessPath)
if newLocation == nil {
// this is a dead link
return nil, fmt.Errorf("no contents for location=%q", location.VirtualPath)
return nil, fmt.Errorf("no contents for location=%q", location.AccessPath)
}
location = *newLocation
case stereoscopeFile.TypeDirectory:
+1 -1
View File
@@ -110,7 +110,7 @@ func (r Directory) FilesByPath(userPaths ...string) ([]file.Location, error) {
continue
}
// we should be resolving symlinks and preserving this information as a VirtualPath to the real file
// we should be resolving symlinks and preserving this information as a AccessPath to the real file
ref, err := r.searchContext.SearchByPath(userStrPath, filetree.FollowBasenameLinks)
if err != nil {
log.Tracef("unable to evaluate symlink for path=%q : %+v", userPath, err)
+138 -138
View File
@@ -65,13 +65,13 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
t.Cleanup(cleanup)
cases := []struct {
name string
cwd string
root string
base string
input string
expectedRealPath string
expectedVirtualPath string // note: if empty it will be assumed to match the expectedRealPath
name string
cwd string
root string
base string
input string
expectedRealPath string
expectedAccessPath string // note: if empty it will be assumed to match the expectedRealPath
}{
{
name: "relative root, relative request, direct",
@@ -139,7 +139,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "path/to/the/file.txt",
expectedVirtualPath: "path/to/the/file.txt",
expectedAccessPath: "path/to/the/file.txt",
},
{
name: "abs root, relative request, direct, cwd within symlink root",
@@ -159,7 +159,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "path/to/the/file.txt",
expectedVirtualPath: "path/to/the/file.txt",
expectedAccessPath: "path/to/the/file.txt",
},
{
name: "abs root, abs request, direct, cwd within symlink root",
@@ -180,7 +180,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "to/the/file.txt",
expectedVirtualPath: "to/the/file.txt",
expectedAccessPath: "to/the/file.txt",
},
{
name: "abs root, relative nested request, direct, cwd within symlink root",
@@ -200,7 +200,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "to/the/file.txt",
expectedVirtualPath: "to/the/file.txt",
expectedAccessPath: "to/the/file.txt",
},
{
name: "abs root, abs nested request, direct, cwd within symlink root",
@@ -221,7 +221,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "path/to/the/file.txt",
expectedVirtualPath: "path/to/the/file.txt",
expectedAccessPath: "path/to/the/file.txt",
},
{
name: "abs root, relative request, direct, cwd within (double) symlink root",
@@ -241,7 +241,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "path/to/the/file.txt",
expectedVirtualPath: "path/to/the/file.txt",
expectedAccessPath: "path/to/the/file.txt",
},
{
name: "abs root, abs request, direct, cwd within (double) symlink root",
@@ -262,7 +262,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "to/the/file.txt",
expectedVirtualPath: "to/the/file.txt",
expectedAccessPath: "to/the/file.txt",
},
{
name: "abs root, relative nested request, direct, cwd within (double) symlink root",
@@ -282,7 +282,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "to/the/file.txt",
expectedVirtualPath: "to/the/file.txt",
expectedAccessPath: "to/the/file.txt",
},
{
name: "abs root, abs nested request, direct, cwd within (double) symlink root",
@@ -303,7 +303,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "to/the/file.txt",
expectedVirtualPath: "to/the/file.txt",
expectedAccessPath: "to/the/file.txt",
},
{
name: "abs root, relative nested request, direct, cwd deep within (double) symlink root",
@@ -323,7 +323,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
// outside the root.
expectedRealPath: filepath.Join(absolute, "path/to/the/file.txt"),
//expectedRealPath: "to/the/file.txt",
expectedVirtualPath: "to/the/file.txt",
expectedAccessPath: "to/the/file.txt",
},
{
name: "abs root, abs nested request, direct, cwd deep within (double) symlink root",
@@ -334,163 +334,163 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
},
// link to outside of root cases...
{
name: "relative root, relative request, abs indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "relative root, relative request, abs indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "abs root, relative request, abs indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "abs root, relative request, abs indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "relative root, abs request, abs indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "relative root, abs request, abs indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "abs root, abs request, abs indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "abs root, abs request, abs indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "relative root, relative request, relative indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "relative root, relative request, relative indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, relative request, relative indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "abs root, relative request, relative indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "relative root, abs request, relative indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "relative root, abs request, relative indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, abs request, relative indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "abs root, abs request, relative indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
// link to outside of root cases... cwd within symlink root
{
name: "relative root, relative request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "relative root, relative request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "abs root, relative request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "abs root, relative request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "relative root, abs request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "relative root, abs request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "abs root, abs request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "abs root, abs request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "relative root, relative request, relative indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "relative root, relative request, relative indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, relative request, relative indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "abs root, relative request, relative indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "relative root, abs request, relative indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "relative root, abs request, relative indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, abs request, relative indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "abs root, abs request, relative indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "relative root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
cwd: relativeViaDoubleLink,
root: "path",
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "relative root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
cwd: relativeViaDoubleLink,
root: "path",
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
cwd: relativeViaDoubleLink,
root: filepath.Join(absolute, "path"),
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "abs root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
cwd: relativeViaDoubleLink,
root: filepath.Join(absolute, "path"),
input: "to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "relative root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
cwd: relativeViaDoubleLink,
root: "path",
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "relative root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
cwd: relativeViaDoubleLink,
root: "path",
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
cwd: relativeViaDoubleLink,
root: filepath.Join(absolute, "path"),
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/rel-outside.txt",
name: "abs root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
cwd: relativeViaDoubleLink,
root: filepath.Join(absolute, "path"),
input: "/to/the/rel-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/rel-outside.txt",
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
if c.expectedVirtualPath == "" {
c.expectedVirtualPath = c.expectedRealPath
if c.expectedAccessPath == "" {
c.expectedAccessPath = c.expectedRealPath
}
// we need to mimic a shell, otherwise we won't get a path within a symlink
@@ -515,7 +515,7 @@ func TestDirectoryResolver_FilesByPath_request_response(t *testing.T) {
}
require.Len(t, refs, 1)
assert.Equal(t, c.expectedRealPath, refs[0].RealPath, "real path different")
assert.Equal(t, c.expectedVirtualPath, refs[0].VirtualPath, "virtual path different")
assert.Equal(t, c.expectedAccessPath, refs[0].AccessPath, "virtual path different")
})
}
}
@@ -961,14 +961,14 @@ func Test_IndexingNestedSymLinks(t *testing.T) {
require.NoError(t, err)
require.Len(t, locations, 1)
assert.Equal(t, "readme", locations[0].RealPath)
assert.Equal(t, "link_to_new_readme", locations[0].VirtualPath)
assert.Equal(t, "link_to_new_readme", locations[0].AccessPath)
// check that we can access the same file via 2 symlinks
locations, err = resolver.FilesByPath("./link_to_link_to_new_readme")
require.NoError(t, err)
require.Len(t, locations, 1)
assert.Equal(t, "readme", locations[0].RealPath)
assert.Equal(t, "link_to_link_to_new_readme", locations[0].VirtualPath)
assert.Equal(t, "link_to_link_to_new_readme", locations[0].AccessPath)
// check that we can access the same file via 2 symlinks
locations, err = resolver.FilesByGlob("**/link_*")
@@ -976,7 +976,7 @@ func Test_IndexingNestedSymLinks(t *testing.T) {
require.Len(t, locations, 1) // you would think this is 2, however, they point to the same file, and glob only returns unique files
// returned locations can be in any order
expectedVirtualPaths := []string{
expectedAccessPaths := []string{
"link_to_link_to_new_readme",
//"link_to_new_readme", // we filter out this one because the first symlink resolves to the same file
}
@@ -986,13 +986,13 @@ func Test_IndexingNestedSymLinks(t *testing.T) {
}
actualRealPaths := strset.New()
actualVirtualPaths := strset.New()
actualAccessPaths := strset.New()
for _, a := range locations {
actualVirtualPaths.Add(a.VirtualPath)
actualAccessPaths.Add(a.AccessPath)
actualRealPaths.Add(a.RealPath)
}
assert.ElementsMatch(t, expectedVirtualPaths, actualVirtualPaths.List())
assert.ElementsMatch(t, expectedAccessPaths, actualAccessPaths.List())
assert.ElementsMatch(t, expectedRealPaths, actualRealPaths.List())
}
+1 -1
View File
@@ -83,7 +83,7 @@ func (r *excluding) AllLocations() <-chan file.Location {
}
func locationMatches(location *file.Location, exclusionFn excludeFn) bool {
return exclusionFn(location.RealPath) || exclusionFn(location.VirtualPath)
return exclusionFn(location.RealPath) || exclusionFn(location.AccessPath)
}
func filterLocations(locations []file.Location, err error, exclusionFn excludeFn) ([]file.Location, error) {
@@ -165,8 +165,8 @@ nextPath:
for i := range out {
existing := &out[i]
if existing.RealPath == l.RealPath {
if l.VirtualPath == "" {
existing.VirtualPath = ""
if l.AccessPath == "" {
existing.AccessPath = ""
}
continue nextPath
}
@@ -90,13 +90,13 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
t.Cleanup(cleanup)
cases := []struct {
name string
cwd string
root string
base string
input string
expectedRealPath string
expectedVirtualPath string // if empty, the virtual path should be the same as the real path
name string
cwd string
root string
base string
input string
expectedRealPath string
expectedAccessPath string // if empty, the virtual path should be the same as the real path
}{
{
name: "relative root, relative request, direct",
@@ -319,32 +319,32 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
},
// link to outside of root cases...
{
name: "relative root, relative request, abs indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "relative root, relative request, abs indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "abs root, relative request, abs indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "abs root, relative request, abs indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "relative root, abs request, abs indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "relative root, abs request, abs indirect (outside of root)",
root: filepath.Join(relative, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "abs root, abs request, abs indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "abs root, abs request, abs indirect (outside of root)",
root: filepath.Join(absolute, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "relative root, relative request, relative indirect (outside of root)",
@@ -352,8 +352,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, relative request, relative indirect (outside of root)",
@@ -361,8 +361,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "relative root, abs request, relative indirect (outside of root)",
@@ -370,8 +370,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "/to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, abs request, relative indirect (outside of root)",
@@ -379,41 +379,41 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "/to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
// link to outside of root cases... cwd within symlink root
{
name: "relative root, relative request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "relative root, relative request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "abs root, relative request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "abs root, relative request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "relative root, abs request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "relative root, abs request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: "path",
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "abs root, abs request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedVirtualPath: "to/the/abs-outside.txt",
name: "abs root, abs request, abs indirect (outside of root), cwd within symlink root",
cwd: relativeViaLink,
root: filepath.Join(absolute, "path"),
input: "/to/the/abs-outside.txt",
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
expectedAccessPath: "to/the/abs-outside.txt",
},
{
name: "relative root, relative request, relative indirect (outside of root), cwd within symlink root",
@@ -422,8 +422,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, relative request, relative indirect (outside of root), cwd within symlink root",
@@ -432,8 +432,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "relative root, abs request, relative indirect (outside of root), cwd within symlink root",
@@ -442,8 +442,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "/to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, abs request, relative indirect (outside of root), cwd within symlink root",
@@ -452,8 +452,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "/to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "relative root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
@@ -462,8 +462,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
@@ -472,8 +472,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "relative root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
@@ -482,8 +482,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "/to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
{
name: "abs root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
@@ -492,14 +492,14 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
input: "/to/the/rel-outside.txt",
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
// TODO: the real path is not correct
expectedRealPath: "../somewhere/outside.txt",
expectedVirtualPath: "to/the/rel-outside.txt",
expectedRealPath: "../somewhere/outside.txt",
expectedAccessPath: "to/the/rel-outside.txt",
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
if c.expectedVirtualPath == "" {
c.expectedVirtualPath = c.expectedRealPath
if c.expectedAccessPath == "" {
c.expectedAccessPath = c.expectedRealPath
}
// we need to mimic a shell, otherwise we won't get a path within a symlink
@@ -523,7 +523,7 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
}
require.Len(t, refs, 1)
assert.Equal(t, c.expectedRealPath, refs[0].RealPath, "real path different")
assert.Equal(t, c.expectedVirtualPath, refs[0].VirtualPath, "virtual path different")
assert.Equal(t, c.expectedAccessPath, refs[0].AccessPath, "virtual path different")
})
}
}
@@ -847,14 +847,14 @@ func Test_UnindexedDirectoryResover_IndexingNestedSymLinks(t *testing.T) {
require.NoError(t, err)
require.Len(t, locations, 1)
assert.Equal(t, "readme", locations[0].RealPath)
assert.Equal(t, "link_to_new_readme", locations[0].VirtualPath)
assert.Equal(t, "link_to_new_readme", locations[0].AccessPath)
// check that we can access the same file via 2 symlinks
locations, err = resolver.FilesByPath("./link_to_link_to_new_readme")
require.NoError(t, err)
require.Len(t, locations, 1)
assert.Equal(t, "readme", locations[0].RealPath)
assert.Equal(t, "link_to_link_to_new_readme", locations[0].VirtualPath)
assert.Equal(t, "link_to_link_to_new_readme", locations[0].AccessPath)
// check that we can access the same file via 2 symlinks
locations, err = resolver.FilesByGlob("**/link_*")
@@ -862,7 +862,7 @@ func Test_UnindexedDirectoryResover_IndexingNestedSymLinks(t *testing.T) {
require.Len(t, locations, 1) // you would think this is 2, however, they point to the same file, and glob only returns unique files
// returned locations can be in any order
expectedVirtualPaths := []string{
expectedAccessPaths := []string{
"link_to_link_to_new_readme",
//"link_to_new_readme", // we filter out this one because the first symlink resolves to the same file
}
@@ -872,13 +872,13 @@ func Test_UnindexedDirectoryResover_IndexingNestedSymLinks(t *testing.T) {
}
actualRealPaths := strset.New()
actualVirtualPaths := strset.New()
actualAccessPaths := strset.New()
for _, a := range locations {
actualVirtualPaths.Add(a.VirtualPath)
actualAccessPaths.Add(a.AccessPath)
actualRealPaths.Add(a.RealPath)
}
assert.ElementsMatch(t, expectedVirtualPaths, actualVirtualPaths.List())
assert.ElementsMatch(t, expectedAccessPaths, actualAccessPaths.List())
assert.ElementsMatch(t, expectedRealPaths, actualRealPaths.List())
}