mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
prefer real paths for glob results
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
parent
a5537943fa
commit
06641cfda2
@ -114,7 +114,8 @@ func (r *AllLayersResolver) FilesByPath(paths ...string) ([]Location, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
uniqueLocations = append(uniqueLocations, NewLocationFromImage(path, result, r.img))
|
// we always prefer the REAL path (not the user given path which may have symlinks)
|
||||||
|
uniqueLocations = append(uniqueLocations, NewLocationFromImage(string(result.RealPath), result, r.img))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,7 +154,8 @@ func (r *AllLayersResolver) FilesByGlob(patterns ...string) ([]Location, error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, refResult := range refResults {
|
for _, refResult := range refResults {
|
||||||
uniqueLocations = append(uniqueLocations, NewLocationFromImage(string(result.MatchPath), refResult, r.img))
|
// we always prefer the REAL path (not the user given path which may have symlinks)
|
||||||
|
uniqueLocations = append(uniqueLocations, NewLocationFromImage(string(refResult.RealPath), refResult, r.img))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -117,6 +117,10 @@ func TestAllLayersResolver_FilesByPath(t *testing.T) {
|
|||||||
t.Errorf("bad resolve path: '%s'!='%s'", string(actual.ref.RealPath), expected.path)
|
t.Errorf("bad resolve path: '%s'!='%s'", string(actual.ref.RealPath), expected.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if expected.path != "" && string(actual.ref.RealPath) != actual.Path {
|
||||||
|
t.Errorf("we should always prefer real paths over ones with links")
|
||||||
|
}
|
||||||
|
|
||||||
entry, err := img.FileCatalog.Get(actual.ref)
|
entry, err := img.FileCatalog.Get(actual.ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to get metadata: %+v", err)
|
t.Fatalf("failed to get metadata: %+v", err)
|
||||||
@ -221,6 +225,10 @@ func TestAllLayersResolver_FilesByGlob(t *testing.T) {
|
|||||||
t.Errorf("bad resolve path: '%s'!='%s'", string(actual.ref.RealPath), expected.path)
|
t.Errorf("bad resolve path: '%s'!='%s'", string(actual.ref.RealPath), expected.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if expected.path != "" && string(actual.ref.RealPath) != actual.Path {
|
||||||
|
t.Errorf("we should always prefer real paths over ones with links")
|
||||||
|
}
|
||||||
|
|
||||||
entry, err := img.FileCatalog.Get(actual.ref)
|
entry, err := img.FileCatalog.Get(actual.ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to get metadata: %+v", err)
|
t.Fatalf("failed to get metadata: %+v", err)
|
||||||
|
|||||||
@ -66,7 +66,8 @@ func (r *ImageSquashResolver) FilesByPath(paths ...string) ([]Location, error) {
|
|||||||
|
|
||||||
if resolvedRef != nil && !uniqueFileIDs.Contains(*resolvedRef) {
|
if resolvedRef != nil && !uniqueFileIDs.Contains(*resolvedRef) {
|
||||||
uniqueFileIDs.Add(*resolvedRef)
|
uniqueFileIDs.Add(*resolvedRef)
|
||||||
uniqueLocations = append(uniqueLocations, NewLocationFromImage(path, *resolvedRef, r.img))
|
// we always prefer the REAL path (not the user given path which may have symlinks)
|
||||||
|
uniqueLocations = append(uniqueLocations, NewLocationFromImage(string(resolvedRef.RealPath), *resolvedRef, r.img))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -106,6 +106,10 @@ func TestImageSquashResolver_FilesByPath(t *testing.T) {
|
|||||||
t.Errorf("bad resolve path: '%s'!='%s'", string(actual.ref.RealPath), c.resolvePath)
|
t.Errorf("bad resolve path: '%s'!='%s'", string(actual.ref.RealPath), c.resolvePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.resolvePath != "" && string(actual.ref.RealPath) != actual.Path {
|
||||||
|
t.Errorf("we should always prefer real paths over ones with links")
|
||||||
|
}
|
||||||
|
|
||||||
entry, err := img.FileCatalog.Get(actual.ref)
|
entry, err := img.FileCatalog.Get(actual.ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to get metadata: %+v", err)
|
t.Fatalf("failed to get metadata: %+v", err)
|
||||||
@ -208,6 +212,10 @@ func TestImageSquashResolver_FilesByGlob(t *testing.T) {
|
|||||||
t.Errorf("bad resolve path: '%s'!='%s'", string(actual.ref.RealPath), c.resolvePath)
|
t.Errorf("bad resolve path: '%s'!='%s'", string(actual.ref.RealPath), c.resolvePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.resolvePath != "" && string(actual.ref.RealPath) != actual.Path {
|
||||||
|
t.Errorf("we should always prefer real paths over ones with links")
|
||||||
|
}
|
||||||
|
|
||||||
entry, err := img.FileCatalog.Get(actual.ref)
|
entry, err := img.FileCatalog.Get(actual.ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to get metadata: %+v", err)
|
t.Fatalf("failed to get metadata: %+v", err)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user