@@ -21,6 +21,13 @@ import (
2121// It also mirrors releases if the option is set.
2222// The function uses goroutines to perform these tasks concurrently and waits for all of them to finish.
2323func (destinationGitlabInstance * GitlabInstance ) updateProjectFromSource (sourceGitlabInstance * GitlabInstance , sourceProject * gitlab.Project , destinationProject * gitlab.Project , copyOptions * utils.MirroringOptions ) []error {
24+ // Immediately capture pointers in local variables to avoid any late overrides
25+ srcProj := sourceProject
26+ dstProj := destinationProject
27+ if srcProj == nil || dstProj == nil {
28+ return []error {fmt .Errorf ("source or destination project is nil" )}
29+ }
30+
2431 wg := sync.WaitGroup {}
2532 maxErrors := 3
2633 if copyOptions .CI_CD_Catalog {
@@ -29,41 +36,43 @@ func (destinationGitlabInstance *GitlabInstance) updateProjectFromSource(sourceG
2936 if copyOptions .MirrorReleases {
3037 maxErrors ++
3138 }
39+
3240 wg .Add (maxErrors )
3341 errorChan := make (chan error , maxErrors )
3442
35- go func () {
43+ go func (sp * gitlab. Project , dp * gitlab. Project ) {
3644 defer wg .Done ()
37- errorChan <- destinationGitlabInstance .syncProjectAttributes (sourceProject , destinationProject , copyOptions )
38- }()
45+ errorChan <- destinationGitlabInstance .syncProjectAttributes (sp , dp , copyOptions )
46+ }(srcProj , dstProj )
3947
40- go func () {
48+ go func (sp * gitlab. Project , dp * gitlab. Project ) {
4149 defer wg .Done ()
42- errorChan <- destinationGitlabInstance .enableProjectMirrorPull (sourceProject , destinationProject , copyOptions )
43- }()
50+ errorChan <- destinationGitlabInstance .enableProjectMirrorPull (sp , dp , copyOptions )
51+ }(srcProj , dstProj )
4452
45- go func () {
53+ go func (sp * gitlab. Project , dp * gitlab. Project ) {
4654 defer wg .Done ()
47- errorChan <- sourceGitlabInstance .copyProjectAvatar (destinationGitlabInstance , destinationProject , sourceProject )
48- }()
55+ errorChan <- sourceGitlabInstance .copyProjectAvatar (destinationGitlabInstance , dp , sp )
56+ }(srcProj , dstProj )
4957
5058 if copyOptions .CI_CD_Catalog {
51- go func () {
59+ go func (dp * gitlab. Project ) {
5260 defer wg .Done ()
53- errorChan <- destinationGitlabInstance .addProjectToCICDCatalog (destinationProject )
54- }()
61+ errorChan <- destinationGitlabInstance .addProjectToCICDCatalog (dp )
62+ }(dstProj )
5563 }
5664
5765 allErrors := []error {}
5866 if copyOptions .MirrorReleases {
59- go func () {
67+ go func (sp * gitlab. Project , dp * gitlab. Project ) {
6068 defer wg .Done ()
61- allErrors = destinationGitlabInstance .mirrorReleases (sourceGitlabInstance , sourceProject , destinationProject )
62- }()
69+ allErrors = destinationGitlabInstance .mirrorReleases (sourceGitlabInstance , sp , dp )
70+ }(srcProj , dstProj )
6371 }
6472
6573 wg .Wait ()
6674 close (errorChan )
75+
6776 for err := range errorChan {
6877 if err != nil {
6978 allErrors = append (allErrors , err )
@@ -176,20 +185,29 @@ func (sourceGitlabInstance *GitlabInstance) copyProjectAvatar(destinationGitlabI
176185// updateGroupFromSource updates the destination group with settings from the source group.
177186// It copies the group avatar and updates the group attributes.
178187func (destinationGitlabInstance * GitlabInstance ) updateGroupFromSource (sourceGitlabInstance * GitlabInstance , sourceGroup * gitlab.Group , destinationGroup * gitlab.Group , copyOptions * utils.MirroringOptions ) []error {
188+ // Immediately capture pointers in local variables to avoid any late overrides
189+ srcGroup := sourceGroup
190+ dstGroup := destinationGroup
191+ cpOpts := copyOptions
192+
193+ if srcGroup == nil || dstGroup == nil {
194+ return []error {fmt .Errorf ("source or destination group is nil" )}
195+ }
196+
179197 wg := sync.WaitGroup {}
180198 maxErrors := 2
181199 wg .Add (maxErrors )
182200 errorChan := make (chan error , maxErrors )
183201
184- go func () {
202+ go func (sg * gitlab. Group , dg * gitlab. Group , cp * utils. MirroringOptions ) {
185203 defer wg .Done ()
186- errorChan <- destinationGitlabInstance .syncGroupAttributes (sourceGroup , destinationGroup , copyOptions )
187- }()
204+ errorChan <- destinationGitlabInstance .syncGroupAttributes (sg , dg , cp )
205+ }(srcGroup , dstGroup , cpOpts )
188206
189- go func () {
207+ go func (sg * gitlab. Group , dg * gitlab. Group ) {
190208 defer wg .Done ()
191- errorChan <- sourceGitlabInstance .copyGroupAvatar (destinationGitlabInstance , destinationGroup , sourceGroup )
192- }()
209+ errorChan <- sourceGitlabInstance .copyGroupAvatar (destinationGitlabInstance , dg , sg )
210+ }(srcGroup , dstGroup )
193211
194212 wg .Wait ()
195213 close (errorChan )
0 commit comments