mirror of
https://github.com/anchore/syft.git
synced 2025-11-19 01:13:18 +01:00
cataloger: add ability to recurse with doublestar
Signed-off-by: Alfredo Deza <adeza@anchore.com>
This commit is contained in:
parent
942cd6eb18
commit
03bbcfa08d
@ -5,10 +5,10 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/anchore/imgbom/internal/log"
|
"github.com/anchore/imgbom/internal/log"
|
||||||
"github.com/anchore/stereoscope/pkg/file"
|
"github.com/anchore/stereoscope/pkg/file"
|
||||||
|
"github.com/bmatcuk/doublestar"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DirectoryResolver struct {
|
type DirectoryResolver struct {
|
||||||
@ -51,7 +51,7 @@ func (s DirectoryResolver) FilesByGlob(patterns ...string) ([]file.Reference, er
|
|||||||
|
|
||||||
for _, pattern := range patterns {
|
for _, pattern := range patterns {
|
||||||
pathPattern := path.Join(s.Path, pattern)
|
pathPattern := path.Join(s.Path, pattern)
|
||||||
matches, err := filepath.Glob(pathPattern)
|
matches, err := doublestar.Glob(pathPattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -138,6 +138,7 @@ func TestDirectoryResolver_FilesByGlobMultiple(t *testing.T) {
|
|||||||
t.Run("finds multiple matching files", func(t *testing.T) {
|
t.Run("finds multiple matching files", func(t *testing.T) {
|
||||||
resolver := DirectoryResolver{"test-fixtures"}
|
resolver := DirectoryResolver{"test-fixtures"}
|
||||||
refs, err := resolver.FilesByGlob("image-symlinks/file*")
|
refs, err := resolver.FilesByGlob("image-symlinks/file*")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not use resolver: %+v, %+v", err, refs)
|
t.Fatalf("could not use resolver: %+v, %+v", err, refs)
|
||||||
}
|
}
|
||||||
@ -149,6 +150,22 @@ func TestDirectoryResolver_FilesByGlobMultiple(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDirectoryResolver_FilesByGlobRecursive(t *testing.T) {
|
||||||
|
t.Run("finds multiple matching files", func(t *testing.T) {
|
||||||
|
resolver := DirectoryResolver{"test-fixtures"}
|
||||||
|
refs, err := resolver.FilesByGlob("**/*.txt")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("could not use resolver: %+v, %+v", err, refs)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(refs) != 4 {
|
||||||
|
t.Errorf("unexpected number of refs: %d != 4", len(refs))
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestDirectoryResolver_FilesByGlobSingle(t *testing.T) {
|
func TestDirectoryResolver_FilesByGlobSingle(t *testing.T) {
|
||||||
t.Run("finds multiple matching files", func(t *testing.T) {
|
t.Run("finds multiple matching files", func(t *testing.T) {
|
||||||
resolver := DirectoryResolver{"test-fixtures"}
|
resolver := DirectoryResolver{"test-fixtures"}
|
||||||
|
|||||||
@ -0,0 +1 @@
|
|||||||
|
file 3
|
||||||
Loading…
x
Reference in New Issue
Block a user