Strip comments and trailing whitespace from grub.cfg to fit modifications
build-and-push / test (push) Successful in 36s
build-and-push / build-and-push (push) Successful in 1m7s

The modified config was 75 bytes larger than the original (5798 vs 5723),
causing the in-place write to be rejected. Strip comment lines and trailing
whitespace to reclaim space for the added auto-installer kernel parameters.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-14 17:05:26 -04:00
parent 82c637ccbb
commit fa570b1571
+22 -1
View File
@@ -114,6 +114,11 @@ func rewriteGrubConfig(original, answerURL string) string {
for _, line := range lines { for _, line := range lines {
trimmed := strings.TrimSpace(line) trimmed := strings.TrimSpace(line)
// Strip comments to reclaim space for added kernel parameters
if strings.HasPrefix(trimmed, "#") {
continue
}
if strings.HasPrefix(trimmed, "set timeout=") { if strings.HasPrefix(trimmed, "set timeout=") {
result = append(result, "set timeout=0") result = append(result, "set timeout=0")
continue continue
@@ -143,10 +148,26 @@ func rewriteGrubConfig(original, answerURL string) string {
} }
} }
line = strings.TrimRight(line, " \t")
result = append(result, line) result = append(result, line)
} }
return strings.Join(result, "\n") // Collapse consecutive blank lines
var collapsed []string
prevBlank := false
for _, line := range result {
if line == "" {
if !prevBlank {
collapsed = append(collapsed, line)
}
prevBlank = true
} else {
collapsed = append(collapsed, line)
prevBlank = false
}
}
return strings.Join(collapsed, "\n")
} }
// findAllOccurrences searches the entire ISO file for all locations where // findAllOccurrences searches the entire ISO file for all locations where