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
|
||||
|
||||
if changed {
|
||||
err = fs.IterateEntries(
|
||||
ctx,
|
||||
dir,
|
||||
func(innerCtx context.Context, entry fs.Entry) error {
|
||||
dEntry, ok := entry.(fs.Directory)
|
||||
if !ok {
|
||||
hasItems = true
|
||||
return nil
|
||||
}
|
||||
iter, err := dir.Iterate(ctx)
|
||||
if err != nil {
|
||||
return clues.WrapWC(ctx, err, "getting directory iterator")
|
||||
}
|
||||
|
||||
var entry fs.Entry
|
||||
|
||||
// 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 {
|
||||
return clues.WrapWC(ctx, err, "traversing base directory")
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user