Skip to content

Commit

Permalink
Use unambiguous backreferences
Browse files Browse the repository at this point in the history
Fixes #16
  • Loading branch information
johnramsden committed Nov 29, 2018
1 parent 90d3a31 commit 2c31897
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions zedenv/plugins/systemdboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,28 +126,33 @@ def edit_bootloader_entry(self, temp_esp: str):
with open(real_bootloader_file, "r") as old_conf:
old_conf_list = old_conf.readlines()

old_be_string = str(self.old_boot_environment)
be_string = str(self.boot_environment)

# replace title
replace_title_pattern = r'(title)(\s*)(.*)({boot_env})(.*$)'.format(
boot_env=self.old_boot_environment)
boot_env=old_be_string)

new_conf_list = self.__config_replace(old_conf_list, replace_title_pattern,
r"\1\2\3" + self.boot_environment + r"\5")
new_conf_list = self.__config_replace(
old_conf_list, replace_title_pattern,
r"\g<1>\g<2>\g<3>" + be_string + r"\g<5>")

# First replace 'linux, initrd' entries
replace_linux_pattern = (
r'(linux|initrd)(\s*)(/env/zedenv-)({boot_env})(/.*$)'
).format(boot_env=self.old_boot_environment)
).format(boot_env=str(old_be_string))

new_conf_list = self.__config_replace(new_conf_list, replace_linux_pattern,
r"\1\2\3" + self.boot_environment + r"\5")
new_conf_list = self.__config_replace(
new_conf_list, replace_linux_pattern,
r"\g<1>\g<2>\g<3>" + be_string + r"\g<5>")

# Replace dataset
replace_ds_pattern = r'(options\s*.*zfs=)({boot_env})(\s*.*$)'.format(
boot_env=f"{self.be_root}/{self.old_boot_environment}")
boot_env=f"{self.be_root}/{old_be_string}")

new_entry_list = self.__config_replace(
new_conf_list, replace_ds_pattern,
r"\1" + f"{self.be_root}/{self.boot_environment}" + r"\3")
r"\g<1>" + f"{self.be_root}/{be_string}" + r"\g<3>")

else:
entry_guess_full = '\n'.join(entry_guess_list)
Expand Down Expand Up @@ -270,8 +275,9 @@ def edit_bootloader_default(self, temp_esp: str, overwrite: bool):
replace_loader_pattern = r'(default)(\s*)(zedenv-{boot_env})(.*$)'.format(
boot_env=self.old_boot_environment)

conf_list = self.__config_replace(conf_list, replace_loader_pattern,
r"\1\2" + f"zedenv-{self.boot_environment}" + r"\4")
conf_list = self.__config_replace(
conf_list, replace_loader_pattern,
r"\g<1>\g<2>" + f"zedenv-{self.boot_environment}" + r"\g<4>")

if not self.noop:
if os.path.isfile(real_loader_conf_path):
Expand Down

0 comments on commit 2c31897

Please sign in to comment.