Skip to content

Commit 76465d9

Browse files
authored
Merge pull request #306 from Bedrock-OSS/develop
Update 1.5.1
2 parents abd33df + c8b04b5 commit 76465d9

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

regolith/export.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,7 @@ func ExportProject(ctx RunContext) error {
275275
MeasureEnd()
276276
// List the names of the filters that opt-in to the data export process
277277
var exportedFilterNames []string
278-
for filter := range profile.Filters {
279-
filter := profile.Filters[filter]
278+
err = profile.ForeachFilter(ctx, func(filter FilterRunner) error {
280279
usingDataPath, err := filter.IsUsingDataExport(dotRegolithPath, ctx)
281280
if err != nil {
282281
return burrito.WrapErrorf(
@@ -299,6 +298,10 @@ func ExportProject(ctx RunContext) error {
299298
// Add the filter name to the list of paths to export
300299
exportedFilterNames = append(exportedFilterNames, filter.GetId())
301300
}
301+
return nil
302+
}, true)
303+
if err != nil {
304+
return burrito.WrapError(err, "Failed to walk the list of the filters.")
302305
}
303306
// The root of the data path cannot be deleted because the
304307
// "regolith watch" function would stop watching the file changes

regolith/profile.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,51 @@ func ProfileFromObject(
322322
result.ExportTarget = exportTarget
323323
return result, nil
324324
}
325+
326+
// ForeachFilter iterates over the filters of the profile and applies the
327+
// given function to each filter. If unpackNestedProfiles is true, it will
328+
// unpack the nested profiles and apply the function to their filters as well.
329+
func (p *Profile) ForeachFilter(
330+
context RunContext,
331+
fn func(FilterRunner) error,
332+
unpackNestedProfiles bool,
333+
) error {
334+
for i := range p.Filters {
335+
filter := p.Filters[i]
336+
profileFilter, ok := filter.(*ProfileFilter)
337+
if unpackNestedProfiles && ok {
338+
subProfile, ok := context.Config.Profiles[profileFilter.Profile]
339+
if !ok {
340+
return burrito.WrappedErrorf(
341+
"Failed to find profile of the profile-filter.\n"+
342+
"Parent profile: %s\n"+
343+
"Profile filter index: %d\n"+
344+
"Referenced profile: %s\n",
345+
context.Profile, i, profileFilter.Profile,
346+
)
347+
}
348+
err := subProfile.ForeachFilter(context, fn, unpackNestedProfiles)
349+
if err != nil {
350+
return burrito.WrappedErrorf(
351+
"Failed to iterate over filters of the profile-filter.\n"+
352+
"Parent profile: %s\n"+
353+
"Profile filter index: %d\n"+
354+
"Referenced profile: %s\n",
355+
context.Profile, i, profileFilter.Profile,
356+
)
357+
}
358+
} else {
359+
err := fn(filter)
360+
if err != nil {
361+
return burrito.WrapErrorf(
362+
err,
363+
"Failed to iterate apply function to the filter.\n"+
364+
"Profile: %s\n"+
365+
"Filter index: %d\n",
366+
context.Profile, i,
367+
)
368+
}
369+
}
370+
}
371+
return nil
372+
}

0 commit comments

Comments
 (0)