Skip to content

Commit

Permalink
Merge pull request #306 from Bedrock-OSS/develop
Browse files Browse the repository at this point in the history
Update 1.5.1
  • Loading branch information
Nusiq authored Dec 16, 2024
2 parents abd33df + c8b04b5 commit 76465d9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
7 changes: 5 additions & 2 deletions regolith/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ func ExportProject(ctx RunContext) error {
MeasureEnd()
// List the names of the filters that opt-in to the data export process
var exportedFilterNames []string
for filter := range profile.Filters {
filter := profile.Filters[filter]
err = profile.ForeachFilter(ctx, func(filter FilterRunner) error {
usingDataPath, err := filter.IsUsingDataExport(dotRegolithPath, ctx)
if err != nil {
return burrito.WrapErrorf(
Expand All @@ -299,6 +298,10 @@ func ExportProject(ctx RunContext) error {
// Add the filter name to the list of paths to export
exportedFilterNames = append(exportedFilterNames, filter.GetId())
}
return nil
}, true)
if err != nil {
return burrito.WrapError(err, "Failed to walk the list of the filters.")
}
// The root of the data path cannot be deleted because the
// "regolith watch" function would stop watching the file changes
Expand Down
48 changes: 48 additions & 0 deletions regolith/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,51 @@ func ProfileFromObject(
result.ExportTarget = exportTarget
return result, nil
}

// ForeachFilter iterates over the filters of the profile and applies the
// given function to each filter. If unpackNestedProfiles is true, it will
// unpack the nested profiles and apply the function to their filters as well.
func (p *Profile) ForeachFilter(
context RunContext,
fn func(FilterRunner) error,
unpackNestedProfiles bool,
) error {
for i := range p.Filters {
filter := p.Filters[i]
profileFilter, ok := filter.(*ProfileFilter)
if unpackNestedProfiles && ok {
subProfile, ok := context.Config.Profiles[profileFilter.Profile]
if !ok {
return burrito.WrappedErrorf(
"Failed to find profile of the profile-filter.\n"+
"Parent profile: %s\n"+
"Profile filter index: %d\n"+
"Referenced profile: %s\n",
context.Profile, i, profileFilter.Profile,
)
}
err := subProfile.ForeachFilter(context, fn, unpackNestedProfiles)
if err != nil {
return burrito.WrappedErrorf(
"Failed to iterate over filters of the profile-filter.\n"+
"Parent profile: %s\n"+
"Profile filter index: %d\n"+
"Referenced profile: %s\n",
context.Profile, i, profileFilter.Profile,
)
}
} else {
err := fn(filter)
if err != nil {
return burrito.WrapErrorf(
err,
"Failed to iterate apply function to the filter.\n"+
"Profile: %s\n"+
"Filter index: %d\n",
context.Profile, i,
)
}
}
}
return nil
}

0 comments on commit 76465d9

Please sign in to comment.