@@ -38,6 +38,7 @@ import (
38
38
"os"
39
39
"path/filepath"
40
40
"sort"
41
+ "strconv"
41
42
"strings"
42
43
)
43
44
@@ -65,11 +66,16 @@ func (s *PlatformKeysRewriteLoader) Run(context map[string]interface{}) error {
65
66
for _ , key := range keys {
66
67
keyParts := strings .Split (key , "." )
67
68
if keyParts [0 ] == constants .PLATFORM_REWRITE_OLD {
69
+ index , err := strconv .Atoi (keyParts [1 ])
70
+ if err != nil {
71
+ return utils .WrapError (err )
72
+ }
68
73
rewriteKey := strings .Join (keyParts [2 :], "." )
69
74
oldValue := txt [key ]
70
75
newValue := txt [constants .PLATFORM_REWRITE_NEW + "." + strings .Join (keyParts [1 :], "." )]
71
76
platformKeyRewrite := types.PlatforKeyRewrite {Key : rewriteKey , OldValue : oldValue , NewValue : newValue }
72
- platformKeysRewrite .Rewrites = append (platformKeysRewrite .Rewrites , platformKeyRewrite )
77
+ platformKeysRewrite .Rewrites = growSliceOfRewrites (platformKeysRewrite .Rewrites , index )
78
+ platformKeysRewrite .Rewrites [index ] = platformKeyRewrite
73
79
}
74
80
}
75
81
@@ -92,3 +98,12 @@ func findPlatformKeysRewriteTxt(folders []string) (string, error) {
92
98
93
99
return constants .EMPTY_STRING , nil
94
100
}
101
+
102
+ func growSliceOfRewrites (originalSlice []types.PlatforKeyRewrite , maxIndex int ) []types.PlatforKeyRewrite {
103
+ if cap (originalSlice ) > maxIndex {
104
+ return originalSlice
105
+ }
106
+ newSlice := make ([]types.PlatforKeyRewrite , maxIndex + 1 )
107
+ copy (newSlice , originalSlice )
108
+ return newSlice
109
+ }
0 commit comments