Rewrite remaining directory iteration during hierarchy merging (#4467)
Switch the remaining call of iterating through directory entries to explicitly use the iterator instead of a helper function that takes a callback Mostly just just to switch everything over to the new iterator and to reduce indentation of things overall --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [x] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [x] 🧹 Tech Debt/Cleanup #### Issue(s) * closes #4457 #### Test Plan - [ ] 💪 Manual - [x] ⚡ Unit test - [x] 💚 E2E
This commit is contained in:
parent
2cd73e2d91
commit
a2e80073be
@ -1122,26 +1122,41 @@ func traverseBaseDir(
|
|||||||
var hasItems bool
|
var hasItems bool
|
||||||
|
|
||||||
if changed {
|
if changed {
|
||||||
err = fs.IterateEntries(
|
iter, err := dir.Iterate(ctx)
|
||||||
ctx,
|
if err != nil {
|
||||||
dir,
|
return clues.WrapWC(ctx, err, "getting directory iterator")
|
||||||
func(innerCtx context.Context, entry fs.Entry) error {
|
}
|
||||||
dEntry, ok := entry.(fs.Directory)
|
|
||||||
if !ok {
|
var entry fs.Entry
|
||||||
hasItems = true
|
|
||||||
return nil
|
// Need to keep err for the check after the loop as well so we also need to
|
||||||
}
|
// declare entry.
|
||||||
|
for entry, err = iter.Next(ctx); entry != nil && err == nil; entry, err = iter.Next(ctx) {
|
||||||
|
dEntry, ok := entry.(fs.Directory)
|
||||||
|
if !ok {
|
||||||
|
hasItems = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
err = traverseBaseDir(
|
||||||
|
ctx,
|
||||||
|
depth+1,
|
||||||
|
updatedPaths,
|
||||||
|
oldDirPath,
|
||||||
|
currentPath,
|
||||||
|
dEntry,
|
||||||
|
roots,
|
||||||
|
stats)
|
||||||
|
if err != nil {
|
||||||
|
// Break here instead of just returning so we can close the iterator.
|
||||||
|
// The error will be returned below.
|
||||||
|
err = clues.Stack(err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
iter.Close()
|
||||||
|
|
||||||
return traverseBaseDir(
|
|
||||||
innerCtx,
|
|
||||||
depth+1,
|
|
||||||
updatedPaths,
|
|
||||||
oldDirPath,
|
|
||||||
currentPath,
|
|
||||||
dEntry,
|
|
||||||
roots,
|
|
||||||
stats)
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return clues.WrapWC(ctx, err, "traversing base directory")
|
return clues.WrapWC(ctx, err, "traversing base directory")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user