mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 17:03:17 +01:00
Include root path in directory resolve index (#869)
This commit is contained in:
parent
a86dd3704e
commit
991af0d857
@ -147,7 +147,7 @@ func (r *directoryResolver) indexPath(path string, info os.FileInfo, err error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// link cycles could cause a revisit --we should not allow this
|
// link cycles could cause a revisit --we should not allow this
|
||||||
if r.fileTree.HasPath(file.Path(path)) {
|
if r.hasBeenIndexed(path) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,6 +193,23 @@ func (r directoryResolver) addPathToIndex(p string, info os.FileInfo) (string, e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r directoryResolver) hasBeenIndexed(p string) bool {
|
||||||
|
filePath := file.Path(p)
|
||||||
|
if !r.fileTree.HasPath(filePath) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
exists, ref, err := r.fileTree.File(filePath)
|
||||||
|
if err != nil || !exists || ref == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// cases like "/" will be in the tree, but not been indexed yet (a special case). We want to capture
|
||||||
|
// these cases as new paths to index.
|
||||||
|
_, exists = r.metadata[ref.ID()]
|
||||||
|
return exists
|
||||||
|
}
|
||||||
|
|
||||||
func (r directoryResolver) addDirectoryToIndex(p string, info os.FileInfo) error {
|
func (r directoryResolver) addDirectoryToIndex(p string, info os.FileInfo) error {
|
||||||
ref, err := r.fileTree.AddDir(file.Path(p))
|
ref, err := r.fileTree.AddDir(file.Path(p))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -848,3 +848,20 @@ func testWithTimeout(t *testing.T, timeout time.Duration, test func(*testing.T))
|
|||||||
case <-done:
|
case <-done:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_IncludeRootPathInIndex(t *testing.T) {
|
||||||
|
filterFn := func(path string, _ os.FileInfo) bool {
|
||||||
|
return path != "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
resolver, err := newDirectoryResolver("/", filterFn)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
exists, ref, err := resolver.fileTree.File(file.Path("/"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, ref)
|
||||||
|
assert.True(t, exists)
|
||||||
|
|
||||||
|
_, exists = resolver.metadata[ref.ID()]
|
||||||
|
require.True(t, exists)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user