Skip to content

Commit 308d00b

Browse files
committed
make name more explicit with processNumShardsWhenSomeIsVariable
1 parent 9027f4d commit 308d00b

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

internal/convert/adv2v2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func convertRepSpecs(resourceb *hclwrite.Body, diskSizeGB hclwrite.Tokens) error
105105
blockb.SetAttributeRaw(nConfig, hcl.TokensArray(configs))
106106
}
107107
if hasVariableShards {
108-
resultTokens = append(resultTokens, processNumShards(shardsAttr, blockb))
108+
resultTokens = append(resultTokens, processNumShardsWhenSomeIsVariable(shardsAttr, blockb))
109109
continue
110110
}
111111
numShardsVal := 1 // Default to 1 if num_shards is not set

internal/convert/clu2adv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func fillRepSpecs(resourceb *hclwrite.Body, root attrVals) error {
200200
return errConfig
201201
}
202202
if hasVariableShards {
203-
resultTokens = append(resultTokens, processNumShards(shardsAttr, specb))
203+
resultTokens = append(resultTokens, processNumShardsWhenSomeIsVariable(shardsAttr, specb))
204204
continue
205205
}
206206
shardsVal, err := hcl.GetAttrInt(shardsAttr, errNumShards)

internal/convert/shared.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ func hasVariableNumShards(blocks []*hclwrite.Block) bool {
2121
return false
2222
}
2323

24-
// processNumShards handles num_shards for a block, returning tokens for the expanded specs.
25-
// processedBody is the body with num_shards removed and other processing done.
26-
func processNumShards(shardsAttr *hclwrite.Attribute, processedBody *hclwrite.Body) hclwrite.Tokens {
24+
// processNumShardsWhenSomeIsVariable handles num_shards when some replication_specs have variable num_shards
25+
func processNumShardsWhenSomeIsVariable(shardsAttr *hclwrite.Attribute, processedBody *hclwrite.Body) hclwrite.Tokens {
2726
if shardsAttr == nil {
2827
return hcl.TokensArraySingle(processedBody) // Default 1 if no num_shards specified
2928
}
@@ -118,11 +117,9 @@ func collectBlocks(body *hclwrite.Body, name string) []*hclwrite.Block {
118117
for _, block := range body.Blocks() {
119118
if block.Type() == name {
120119
blocks = append(blocks, block)
120+
body.RemoveBlock(block)
121121
}
122122
}
123-
for _, block := range blocks {
124-
body.RemoveBlock(block)
125-
}
126123
return blocks
127124
}
128125

0 commit comments

Comments
 (0)