From 8ccc95a473765a6d3bbe7253be3cb7c680aed534 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Thu, 30 Jan 2020 15:51:35 -0800 Subject: [PATCH] Use Blueprint.DeepCopy for blueprints/freeze Without making a deep copy of the blueprint the changes made to the package and module versions will persist in memory, causing it to lose the package and module version globs. This can be seen by executing a freeze request and then a depsolve. The blueprint included in the depsolve had the version globs replaced by the frozen EVRA values. --- internal/weldr/api.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/internal/weldr/api.go b/internal/weldr/api.go index b8c4f86ef..5a77452f6 100644 --- a/internal/weldr/api.go +++ b/internal/weldr/api.go @@ -898,8 +898,8 @@ func (api *API) blueprintsFreezeHandler(writer http.ResponseWriter, request *htt if i == 0 { name = name[1:] } - blueprint, _ := api.store.GetBlueprint(name) - if blueprint == nil { + bp, _ := api.store.GetBlueprint(name) + if bp == nil { rerr := responseError{ ID: "UnknownBlueprint", Msg: fmt.Sprintf("%s: blueprint_not_found", name), @@ -907,8 +907,18 @@ func (api *API) blueprintsFreezeHandler(writer http.ResponseWriter, request *htt errors = append(errors, rerr) break } + // Make a copy of the blueprint since we will be replacing the version globs + blueprint, err := bp.DeepCopy() + if err != nil { + rerr := responseError{ + ID: "BlueprintDeepCopyError", + Msg: fmt.Sprintf("%s: %s", name, err.Error()), + } + errors = append(errors, rerr) + break + } - dependencies, _, _, err := api.depsolveBlueprint(blueprint, "", api.arch, false) + dependencies, _, _, err := api.depsolveBlueprint(&blueprint, "", api.arch, false) if err != nil { rerr := responseError{ ID: "BlueprintsError", @@ -941,7 +951,7 @@ func (api *API) blueprintsFreezeHandler(writer http.ResponseWriter, request *htt errors = append(errors, rerr) break } - blueprints = append(blueprints, blueprintFrozen{*blueprint}) + blueprints = append(blueprints, blueprintFrozen{blueprint}) } json.NewEncoder(writer).Encode(reply{