Strip comments and trailing whitespace from grub.cfg to fit modifications
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:
@@ -114,6 +114,11 @@ func rewriteGrubConfig(original, answerURL string) string {
|
||||
for _, line := range lines {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
|
||||
// Strip comments to reclaim space for added kernel parameters
|
||||
if strings.HasPrefix(trimmed, "#") {
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.HasPrefix(trimmed, "set timeout=") {
|
||||
result = append(result, "set timeout=0")
|
||||
continue
|
||||
@@ -143,10 +148,26 @@ func rewriteGrubConfig(original, answerURL string) string {
|
||||
}
|
||||
}
|
||||
|
||||
line = strings.TrimRight(line, " \t")
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user