[grubcfg] Guard against stupid configurations

- Scenario: *keepDistribution* is true, and the existing file contains
   a GRUB_DISTRIBUTION line **followed** by a commented-out GRUB_DISTRIBUTION
   line.
 - In that case, the commented-out line would change the flag back to
   False, and we'd end up writing a second GRUB_DISTRIBUTION line at the end.

Prevent that: the flag can only go to "True" and then stays there.

Editorial: If your grub configuration would have tripped this up, then
you're doing something wrong. Clean up the configuration file first.
This commit is contained in:
Adriaan de Groot 2019-11-04 16:36:57 +01:00
parent 4a0a8083f3
commit f727362a90

View File

@ -184,7 +184,7 @@ def modify_grub_default(partitions, root_mount_point, distributor):
else:
# We're not updating because of *keepDistributor*, but if
# this was a comment line, then it's still not been set.
have_distributor_line = not lines[i].startsdwith("#")
have_distributor_line = have_distributor_line or not lines[i].startsdwith("#")
else:
lines = []