Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 1.5.1 #306

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}