Skip to content

Commit

Permalink
define filetree interfaces
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
  • Loading branch information
wagoodman committed Jan 30, 2023
1 parent 073c529 commit 4d50b37
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
12 changes: 5 additions & 7 deletions pkg/filetree/filetree.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ var ErrRemovingRoot = errors.New("cannot remove the root path (`/`) from the Fil
var ErrLinkCycleDetected = errors.New("cycle during symlink resolution")

type Reader interface {
AllRealPaths() []file.Path
AllFiles(types ...file.Type) []file.Reference
ListPaths(dir file.Path) ([]file.Path, error)
File(path file.Path, options ...LinkResolutionOption) (bool, *file.ReferenceAccessVia, error)
Reader() tree.Reader
Equal(other *FileTree) bool
PathDiff(other *FileTree) (extra, missing []file.Path)
FilesByGlob(query string, options ...LinkResolutionOption) ([]file.ReferenceAccessVia, error)
// note: there are more reader-like functions, however, let's try to keep this interface small and simple for now
}

type Walker interface {
Walk(fn func(path file.Path, f filenode.FileNode) error, conditions *WalkConditions) error
HasPath(path file.Path, options ...LinkResolutionOption) bool
}

type Writer interface {
Expand Down
8 changes: 4 additions & 4 deletions pkg/filetree/glob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,20 @@ func TestOSAdapter_ReadDir(t *testing.T) {
expected: []fileinfoAdapter{
{
VirtualPath: "/home/thing.txt",
Node: filenode.FileNode{RealPath: "/home/thing.txt", FileType: 48},
Node: filenode.FileNode{RealPath: "/home/thing.txt", FileType: file.TypeReg},
},

{
VirtualPath: "/home/wagoodman",
Node: filenode.FileNode{RealPath: "/home/wagoodman", FileType: 53},
Node: filenode.FileNode{RealPath: "/home/wagoodman", FileType: file.TypeDir},
},
{
VirtualPath: "/home/thing",
Node: filenode.FileNode{RealPath: "/home/thing", FileType: 50, LinkPath: "./thing.txt"},
Node: filenode.FileNode{RealPath: "/home/thing", FileType: file.TypeSymlink, LinkPath: "./thing.txt"},
},
{
VirtualPath: "/home/place",
Node: filenode.FileNode{RealPath: "/home/place", FileType: 49, LinkPath: "/somewhere-else"},
Node: filenode.FileNode{RealPath: "/home/place", FileType: file.TypeHardLink, LinkPath: "/somewhere-else"},
},
},
shouldErr: false,
Expand Down
6 changes: 3 additions & 3 deletions pkg/filetree/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ type Searcher interface {
}

type searchContext struct {
tree *FileTree // this is the tree which all index search results are filtered against
index Index // this index is relative to one or more trees, not just necessarily one
tree Reader // this is the tree which all index search results are filtered against
index Index // this index is relative to one or more trees, not just necessarily one
}

func NewSearchContext(tree *FileTree, index Index) Searcher {
func NewSearchContext(tree Reader, index Index) Searcher {
return &searchContext{
tree: tree,
index: index,
Expand Down

0 comments on commit 4d50b37

Please sign in to comment.