From 4c6acf2301b4148a250bf81c56dec034e3db2710 Mon Sep 17 00:00:00 2001 From: DavHau Date: Wed, 23 Oct 2024 17:37:31 +0700 Subject: [PATCH] cmd.run: add needs_user_terminal to unbreak sudo --- pkgs/clan-cli/clan_cli/cmd.py | 7 +++++-- pkgs/clan-cli/clan_cli/flash/automount.py | 2 +- pkgs/clan-cli/clan_cli/flash/flash.py | 7 ++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/cmd.py b/pkgs/clan-cli/clan_cli/cmd.py index e1395bf13..f3f0f39ec 100644 --- a/pkgs/clan-cli/clan_cli/cmd.py +++ b/pkgs/clan-cli/clan_cli/cmd.py @@ -134,6 +134,7 @@ def run( log: Log = Log.STDERR, check: bool = True, error_msg: str | None = None, + needs_user_terminal: bool = False, ) -> CmdOut: if cwd is None: cwd = Path.cwd() @@ -153,9 +154,11 @@ def run( env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - start_new_session=True, + start_new_session=not needs_user_terminal, ) as process, - terminate_process_group(process), + terminate_process_group(process) + if not needs_user_terminal + else contextlib.suppress(), # NOQA: B022 ): stdout_buf, stderr_buf = handle_output(process, log) diff --git a/pkgs/clan-cli/clan_cli/flash/automount.py b/pkgs/clan-cli/clan_cli/flash/automount.py index d0dda39d4..cd41c32ca 100644 --- a/pkgs/clan-cli/clan_cli/flash/automount.py +++ b/pkgs/clan-cli/clan_cli/flash/automount.py @@ -30,7 +30,7 @@ def pause_automounting(devices: list[Path]) -> Generator[None, None, None]: str_devs = [str(dev) for dev in devices] cmd = ["sudo", str(inhibit_path), "enable", *str_devs] - result = run(cmd, log=Log.BOTH, check=False) + result = run(cmd, log=Log.BOTH, check=False, needs_user_terminal=True) if result.returncode != 0: log.error("Failed to inhibit automounting") yield None diff --git a/pkgs/clan-cli/clan_cli/flash/flash.py b/pkgs/clan-cli/clan_cli/flash/flash.py index 74b7cdfcf..dc110a163 100644 --- a/pkgs/clan-cli/clan_cli/flash/flash.py +++ b/pkgs/clan-cli/clan_cli/flash/flash.py @@ -152,4 +152,9 @@ def flash_machine( ["nixpkgs#disko"], disko_install, ) - run(cmd, log=Log.BOTH, error_msg=f"Failed to flash {machine}") + run( + cmd, + log=Log.BOTH, + error_msg=f"Failed to flash {machine}", + needs_user_terminal=True, + )