Merge pull request 'cmd.run: add needs_user_terminal to unbreak sudo' (#2278) from DavHau/clan-core:DavHau-dave into main

This commit is contained in:
clan-bot
2024-10-23 10:43:37 +00:00
3 changed files with 12 additions and 4 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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,
)