From c087c856428a02fa737b944e0c8d06cea48ea9f2 Mon Sep 17 00:00:00 2001 From: Evan Cordell Date: Wed, 10 Jul 2024 15:38:11 -0400 Subject: [PATCH] fix: cloning a channel copied the edge slice instead of cloning --- go.mod | 1 + go.sum | 2 ++ pkg/updates/file.go | 7 +++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 3df6f943..e360c506 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/fatih/camelcase v1.0.0 github.com/go-logr/logr v1.4.2 github.com/jzelinskie/stringz v0.0.3 + github.com/samber/lo v1.44.0 github.com/spf13/cobra v1.8.1 github.com/stretchr/testify v1.9.0 go.uber.org/atomic v1.11.0 diff --git a/go.sum b/go.sum index 89288d4a..01b090d1 100644 --- a/go.sum +++ b/go.sum @@ -168,6 +168,8 @@ github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/samber/lo v1.44.0 h1:5il56KxRE+GHsm1IR+sZ/6J42NODigFiqCWpSc2dybA= +github.com/samber/lo v1.44.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= diff --git a/pkg/updates/file.go b/pkg/updates/file.go index 5515c8a2..e89e64c8 100644 --- a/pkg/updates/file.go +++ b/pkg/updates/file.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/jzelinskie/stringz" + "github.com/samber/lo" "golang.org/x/exp/maps" "golang.org/x/exp/slices" "k8s.io/apimachinery/pkg/util/sets" @@ -45,8 +46,10 @@ func (c Channel) Clone() Channel { return Channel{ Name: c.Name, Metadata: maps.Clone(c.Metadata), - Edges: maps.Clone(c.Edges), - Nodes: slices.Clone(c.Nodes), + Edges: lo.MapEntries(c.Edges, func(k string, v []string) (string, []string) { + return k, slices.Clone(v) + }), + Nodes: slices.Clone(c.Nodes), } }