etc_locale = root / "etc/locale.conf"
- try:
- etc_locale.unlink()
- except FileNotFoundError:
- pass
+ etc_locale.unlink(missing_ok=True)
# Let's ensure we use a UTF-8 locale everywhere.
etc_locale.write_text("LANG=C.UTF-8\n")
# symlink or suchlike. Also if no hostname is configured we really
# don't want the file to exist, so that systemd's implicit
# hostname logic can take effect.
- try:
- os.unlink(etc_hostname)
- except FileNotFoundError:
- pass
+ etc_hostname.unlink(missing_ok=True)
if state.config.hostname:
with complete_step("Assigning hostname"):
with complete_step("Resetting machine ID"):
if not state.config.machine_id:
machine_id = state.root / "etc/machine-id"
- try:
- machine_id.unlink()
- except FileNotFoundError:
- pass
+ machine_id.unlink(missing_ok=True)
machine_id.write_text("uninitialized\n")
dbus_machine_id = state.root / "var/lib/dbus/machine-id"
if "systemd" in extra_packages and "systemd-resolved" not in extra_packages:
# The default resolv.conf points to 127.0.0.1, and resolved is disabled, fix it in
# the base image.
- # TODO: use missing_ok=True when we drop Python << 3.8
- if state.root.joinpath("etc/resolv.conf").exists():
- state.root.joinpath("etc/resolv.conf").unlink()
+ state.root.joinpath("etc/resolv.conf").unlink(missing_ok=True)
state.root.joinpath("etc/resolv.conf").symlink_to("../run/systemd/resolve/resolv.conf")
run(["systemctl", "--root", state.root, "enable", "systemd-resolved"])
# Debian/Ubuntu use a different path to store the locale so let's make sure that path is a symlink to
# etc/locale.conf.
- try:
- state.root.joinpath("etc/default/locale").unlink()
- except FileNotFoundError:
- pass
+ state.root.joinpath("etc/default/locale").unlink(missing_ok=True)
state.root.joinpath("etc/default/locale").symlink_to("../locale.conf")
@classmethod