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:
ashmrtn 2023-12-04 11:33:52 -08:00 committed by GitHub
parent 2cd73e2d91
commit a2e80073be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1122,18 +1122,24 @@ 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 { }
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) dEntry, ok := entry.(fs.Directory)
if !ok { if !ok {
hasItems = true hasItems = true
return nil continue
} }
return traverseBaseDir( err = traverseBaseDir(
innerCtx, ctx,
depth+1, depth+1,
updatedPaths, updatedPaths,
oldDirPath, oldDirPath,
@ -1141,7 +1147,16 @@ func traverseBaseDir(
dEntry, dEntry,
roots, roots,
stats) 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()
if err != nil { if err != nil {
return clues.WrapWC(ctx, err, "traversing base directory") return clues.WrapWC(ctx, err, "traversing base directory")
} }