Skip to content

Commit 7f9cf34

Browse files
derek10cloudgeneral-kroll-4-life
authored andcommitted
support overwrite with registry pull
1 parent 6e37779 commit 7f9cf34

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

internal/stackql/planbuilder/plan_builder.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -647,9 +647,7 @@ func (pgb *standardPlanGraphBuilder) handleDelete(pbi planbuilderinput.PlanBuild
647647
}
648648

649649
//nolint:gocognit // acceptable
650-
func (pgb *standardPlanGraphBuilder) handleRegistry(
651-
pbi planbuilderinput.PlanBuilderInput,
652-
) error {
650+
func (pgb *standardPlanGraphBuilder) handleRegistry(pbi planbuilderinput.PlanBuilderInput) error {
653651
handlerCtx := pbi.GetHandlerCtx()
654652
node, ok := pbi.GetRegistry()
655653
if !ok {
@@ -672,14 +670,32 @@ func (pgb *standardPlanGraphBuilder) handleRegistry(
672670
providerVersion := node.ProviderVersion
673671
if providerVersion == "" {
674672
providerVersion, err = reg.GetLatestPublishedVersion(node.ProviderId)
673+
if err != nil {
674+
return internaldto.NewErroneousExecutorOutput(err)
675+
}
675676
}
676-
if err != nil {
677+
678+
// Get all existing versions from local filesystem
679+
localProviders := reg.ListLocallyAvailableProviders()
680+
if providerDesc, exists := localProviders[node.ProviderId]; exists {
681+
// Remove all existing versions
682+
for _, version := range providerDesc.Versions {
683+
if err := reg.RemoveProviderVersion(node.ProviderId, version); err != nil {
684+
return internaldto.NewErroneousExecutorOutput(err)
685+
}
686+
}
687+
}
688+
689+
// Clear provider cache before pulling new version
690+
if err := reg.ClearProviderCache(node.ProviderId); err != nil {
677691
return internaldto.NewErroneousExecutorOutput(err)
678692
}
679-
err = reg.PullAndPersistProviderArchive(node.ProviderId, providerVersion)
680-
if err != nil {
693+
694+
// Pull and persist the requested version
695+
if err := reg.PullAndPersistProviderArchive(node.ProviderId, providerVersion); err != nil {
681696
return internaldto.NewErroneousExecutorOutput(err)
682697
}
698+
683699
return util.PrepareResultSet(
684700
internaldto.NewPrepareResultSetPlusRawDTO(
685701
nil, nil, nil, nil, nil,

0 commit comments

Comments
 (0)