deb: change ui/ux of pkh deb
CI / build (push) Successful in 2m54s
CI / test (push) Skipped
CI / snap (push) Failing after 12s

This commit is contained in:
2026-08-22 22:26:20 +02:00
parent e2d201d815
commit e5adf600c3
16 changed files with 1899 additions and 199 deletions
+87 -76
View File
@@ -1,6 +1,6 @@
/// Schroot context: execute commands in a schroot session
/// Not tested, will need more work!
use super::api::ContextDriver;
use super::api::{ContextDriver, LineSink};
use std::io;
use std::path::{Path, PathBuf};
use std::sync::Arc;
@@ -72,6 +72,71 @@ impl SchrootDriver {
.trim()
.to_string())
}
/// Build the `schroot` argument list executing `(program, args)` inside
/// the given session.
///
/// When `preserve_env` is set, `-p` is passed so the host environment is
/// preserved (historical behavior of `run()`, while `run_output()` does
/// not preserve it).
fn schroot_args(
session_id: &str,
preserve_env: bool,
program: &str,
args: &[String],
env: &[(String, String)],
cwd: Option<&str>,
) -> Vec<String> {
let mut command_args = Vec::new();
if preserve_env {
command_args.push("-p".to_string());
}
command_args.extend([
"-r".to_string(),
"-c".to_string(),
session_id.to_string(),
"--".to_string(),
]);
let (actual_program, actual_args) = Self::wrap_command(program, args, env, cwd);
command_args.push(actual_program);
command_args.extend(actual_args);
command_args
}
/// Wrap `(program, args)` in `sh -c` when a working directory or
/// environment variables are needed.
fn wrap_command(
program: &str,
args: &[String],
env: &[(String, String)],
cwd: Option<&str>,
) -> (String, Vec<String>) {
let mut actual_program = program.to_string();
let mut actual_args = args.to_vec();
if cwd.is_some() || !env.is_empty() {
let mut shell_cmd = String::new();
if let Some(dir) = cwd {
shell_cmd.push_str(&format!("cd {} && ", dir));
}
if !env.is_empty() {
shell_cmd.push_str("env ");
for (k, v) in env {
shell_cmd.push_str(&format!("{}={} ", k, v));
}
}
shell_cmd.push_str(&format!("{} {}", program, args.join(" ")));
actual_program = "sh".to_string();
actual_args = vec!["-c".to_string(), shell_cmd];
}
(actual_program, actual_args)
}
}
impl ContextDriver for SchrootDriver {
@@ -119,47 +184,26 @@ impl ContextDriver for SchrootDriver {
cwd: Option<&str>,
) -> io::Result<std::process::ExitStatus> {
let session_id = self.ensure_session()?;
let cmd_args = Self::schroot_args(&session_id, true, program, args, env, cwd);
self.parent().command("schroot").args(cmd_args).status()
}
// Construct the schroot command
// schroot -p -r -c session_id -- program args...
// If cwd is specified, we wrap in sh -c "cd cwd && ..."
let mut command_args = vec![
"-p".to_string(),
"-r".to_string(),
"-c".to_string(),
session_id,
"--".to_string(),
];
let mut actual_program = program.to_string();
let mut actual_args = args.to_vec();
// Simplest: Wrap everything in `sh -c` if CWD or ENV is needed.
if cwd.is_some() || !env.is_empty() {
let mut shell_cmd = String::new();
if let Some(dir) = cwd {
shell_cmd.push_str(&format!("cd {} && ", dir));
}
if !env.is_empty() {
shell_cmd.push_str("env ");
for (k, v) in env {
shell_cmd.push_str(&format!("{}={} ", k, v));
}
}
shell_cmd.push_str(&format!("{} {}", program, args.join(" ")));
actual_program = "sh".to_string();
actual_args = vec!["-c".to_string(), shell_cmd];
}
command_args.push(actual_program);
command_args.extend(actual_args);
self.parent().command("schroot").args(command_args).status()
fn run_captured(
&self,
program: &str,
args: &[String],
env: &[(String, String)],
cwd: Option<&str>,
sink: Arc<dyn LineSink>,
) -> io::Result<std::process::ExitStatus> {
let session_id = self.ensure_session()?;
let cmd_args = Self::schroot_args(&session_id, true, program, args, env, cwd);
// Forward the sink to the wrapping command so capture chains through
// the parent context driver (e.g. schroot over ssh).
let parent = self.parent();
let mut cmd = parent.command("schroot");
cmd.args(cmd_args).capture(sink);
cmd.status()
}
fn run_output(
@@ -170,41 +214,8 @@ impl ContextDriver for SchrootDriver {
cwd: Option<&str>,
) -> io::Result<std::process::Output> {
let session_id = self.ensure_session()?;
let mut command_args = vec![
"-r".to_string(),
"-c".to_string(),
session_id,
"--".to_string(),
];
let mut actual_program = program.to_string();
let mut actual_args = args.to_vec();
if cwd.is_some() || !env.is_empty() {
let mut shell_cmd = String::new();
if let Some(dir) = cwd {
shell_cmd.push_str(&format!("cd {} && ", dir));
}
if !env.is_empty() {
shell_cmd.push_str("env ");
for (k, v) in env {
shell_cmd.push_str(&format!("{}={} ", k, v));
}
}
shell_cmd.push_str(&format!("{} {}", program, args.join(" ")));
actual_program = "sh".to_string();
actual_args = vec!["-c".to_string(), shell_cmd];
}
command_args.push(actual_program);
command_args.extend(actual_args);
self.parent().command("schroot").args(command_args).output()
let cmd_args = Self::schroot_args(&session_id, false, program, args, env, cwd);
self.parent().command("schroot").args(cmd_args).output()
}
fn create_temp_dir(&self) -> io::Result<String> {