Skip to content

Commit

Permalink
feat(nav): set maximum traversal depth (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Dec 28, 2023
1 parent 260c792 commit ae14253
Show file tree
Hide file tree
Showing 10 changed files with 322 additions and 26 deletions.
6 changes: 6 additions & 0 deletions xfs/nav/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ type resumeTE struct {
log bool
}

type cascadeTE struct {
naviTE
skim bool
depth uint
}

type resumeTestProfile struct {
filtered bool
prohibited map[string]string
Expand Down
8 changes: 7 additions & 1 deletion xfs/nav/navigation-periscope.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ func (p *navigationPeriscope) difference(root, current string) {
p._offset = currentSize - rootSize
}

func (p *navigationPeriscope) descend() {
func (p *navigationPeriscope) descend(max uint) bool {
if max > 0 && p._depth > int(max) {
return false
}

p._depth++

return true
}

func (p *navigationPeriscope) ascend() {
Expand Down
17 changes: 12 additions & 5 deletions xfs/nav/navigator-abstract.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,21 @@ func (n *navigator) logger() log.Logger {
return n.log.Get()
}

func (n *navigator) descend(navi *NavigationInfo) {
navi.frame.periscope.descend()
func (n *navigator) descend(navi *NavigationInfo) bool {
if !navi.frame.periscope.descend(n.o.Store.Behaviours.Cascade.Depth) {
return false
}

navi.frame.notifiers.descend.invoke(navi.Item)

return true
}

func (n *navigator) ascend(navi *NavigationInfo) {
navi.frame.periscope.ascend()
navi.frame.notifiers.ascend.invoke(navi.Item)
func (n *navigator) ascend(navi *NavigationInfo, permit bool) {
if permit {
navi.frame.periscope.ascend()
navi.frame.notifiers.ascend.invoke(navi.Item)
}
}

func (n *navigator) finish() error {
Expand Down
14 changes: 9 additions & 5 deletions xfs/nav/navigator-files.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,25 @@ func (n *filesNavigator) traverse(params *traverseParams) (*TraverseItem, error)
Item: params.current,
frame: params.frame,
}
params.navi = navi
descended := n.descend(navi)

//
// For files, the registered callback will only be invoked for file entries. This means
// that the client will have no way to skip the descending of a particular directory. In
// this case, the client should use the OnDescend callback (yet to be implemented) and
// return SkipDir from there.
defer func() {
defer func(permit bool) {
if n.samplingFilterActive {
delete(n.agent.cache, params.current.key())
}

n.ascend(navi)
}()
n.ascend(navi, permit)
}(descended)

params.navi = navi
n.descend(navi)
if !descended {
return nil, nil
}

stash := n.inspect(params)

Expand Down
15 changes: 10 additions & 5 deletions xfs/nav/navigator-folders.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,21 @@ func (n *foldersNavigator) traverse(params *traverseParams) (*TraverseItem, erro
Item: params.current,
frame: params.frame,
}
defer func() {

params.navi = navi
descended := n.descend(navi)

defer func(permit bool) {
if n.samplingFilterActive {
delete(n.agent.cache, params.current.key())
}

n.ascend(navi)
}()
n.ascend(navi, permit)
}(descended)

params.navi = navi
n.descend(navi)
if !descended {
return nil, nil
}

stash := n.inspect(params)
entries := stash.entries
Expand Down
14 changes: 9 additions & 5 deletions xfs/nav/navigator-universal.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,20 @@ func (n *universalNavigator) traverse(params *traverseParams) (*TraverseItem, er
frame: params.frame,
}

defer func() {
params.navi = navi
descended := n.descend(navi)

defer func(permit bool) {
if n.samplingFilterActive {
delete(n.agent.cache, params.current.key())
}

n.ascend(navi)
}()
n.ascend(navi, permit)
}(descended)

params.navi = navi
n.descend(navi)
if !descended {
return nil, nil
}

stash := n.inspect(params)
entries := stash.entries
Expand Down
6 changes: 3 additions & 3 deletions xfs/nav/sampling-while-iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (i *directoryEntryWhileIt) start(entries []fs.DirEntry) {
func (i *directoryEntryWhileIt) sample(entries []fs.DirEntry, processingFiles bool) []fs.DirEntry {
i.start(entries)

result := i.loop()
result := i.enumerate()

return lo.Ternary[[]fs.DirEntry](processingFiles, result.Files, result.Folders)
}
Expand All @@ -148,15 +148,15 @@ func (i *directoryEntryWhileIt) samples(
) (files, folders []fs.DirEntry) {
i.start(sourceEntries.All())

result := i.loop()
result := i.enumerate()

files = result.Files
folders = result.Folders

return
}

func (i *directoryEntryWhileIt) loop() *DirectoryContents {
func (i *directoryEntryWhileIt) enumerate() *DirectoryContents {
result := newEmptyDirectoryEntries(i.o, &i.o.Store.Sampling.NoOf)
parent := i.tp.current

Expand Down
Loading

0 comments on commit ae14253

Please sign in to comment.