From: Daan De Meyer Date: Sat, 5 Aug 2023 16:20:42 +0000 (+0200) Subject: Get rid of check_root() function X-Git-Tag: v15~33^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d80b2aa60dc551e57e8bbc0fdc77f4716837f3a;p=thirdparty%2Fmkosi.git Get rid of check_root() function Only has one call site so let's just inline it. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 028d90395..2bd8a4950 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -1736,11 +1736,6 @@ def acl_toggle_build(config: MkosiConfig, uid: int) -> Iterator[None]: yield -def check_root() -> None: - if os.getuid() != 0: - die("Must be invoked as root.") - - @contextlib.contextmanager def acl_toggle_boot(config: MkosiConfig, uid: int) -> Iterator[None]: if not config.acl or config.output_format != OutputFormat.directory: @@ -1927,8 +1922,8 @@ def prepend_to_environ_path(config: MkosiConfig) -> Iterator[None]: def run_verb(args: MkosiArgs, presets: Sequence[MkosiConfig]) -> None: - if args.verb.needs_sudo(): - check_root() + if args.verb.needs_root() and os.getuid() != 0: + die(f"Must be root to run the {args.verb} command") if args.verb == Verb.genkey: return generate_key_cert_pair(args) diff --git a/mkosi/config.py b/mkosi/config.py index 9ebcd38d9..5c1b44010 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -64,7 +64,7 @@ class Verb(StrEnum): def needs_build(self) -> bool: return self in (Verb.build, Verb.shell, Verb.boot, Verb.qemu, Verb.serve) - def needs_sudo(self) -> bool: + def needs_root(self) -> bool: return self in (Verb.shell, Verb.boot)