fix(installer): make the Linux half of Phase 2 compile
All checks were successful
PR Checks / rust-gates (pull_request) Successful in 1m56s

Three faults in code that only compiles under cfg(unix), none of which the
Windows build could see:

- `run(...).map(...) == Ok(true)` compared two `Result<_, anyhow::Error>`
  values, and anyhow::Error is not PartialEq. Replaced with `is_ok_and`.
- `command_line` is used only by the Windows registration path, so importing it
  unconditionally is an unused-import error under `-D warnings`. Qualified at
  its call site instead.
- A cfg(not(windows)) assertion block had ended up in the wrong test, leaving it
  referencing a binding from its original one.

Caught by running the same gates the CI runner does inside a rust:1-slim
container against this working tree — fmt, clippy --all-targets -D warnings, and
cargo test --locked all pass there now, as they do on Windows.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-08-04 15:52:02 -05:00
parent 2228e0848b
commit 7bfb033957

View File

@@ -31,7 +31,9 @@ use std::path::{Path, PathBuf};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use crate::util::{command_line, run, run_ok}; // `command_line` is used only by the Windows registration path, so it is qualified at its call
// site rather than imported here — an unconditional import is an unused-import error on Linux.
use crate::util::{run, run_ok};
/// The unit file name, and the systemd service name with its suffix. /// The unit file name, and the systemd service name with its suffix.
pub const SYSTEMD_UNIT: &str = "runicgateway-link.service"; pub const SYSTEMD_UNIT: &str = "runicgateway-link.service";
@@ -149,7 +151,7 @@ fn prepare_platform() -> Prepared {
/// Creates the dedicated system user if it is not already there. Returns whether it created it. /// Creates the dedicated system user if it is not already there. Returns whether it created it.
#[cfg(unix)] #[cfg(unix)]
fn ensure_user(user: &str) -> Result<bool> { fn ensure_user(user: &str) -> Result<bool> {
if run("id", &["-u", user]).map(|o| o.status.success()) == Ok(true) { if run("id", &["-u", user]).is_ok_and(|o| o.status.success()) {
return Ok(false); return Ok(false);
} }
// `useradd` is the near-universal spelling; `adduser` is the fallback for Debian's wrapper and // `useradd` is the near-universal spelling; `adduser` is the fallback for Debian's wrapper and
@@ -373,7 +375,7 @@ fn register_windows(binary: &Path, config: &Path, restart: bool) -> Result<Outco
anyhow::bail!( anyhow::bail!(
"`{}` failed with exit code {}. Check the Windows event log; a service that exits \ "`{}` failed with exit code {}. Check the Windows event log; a service that exits \
immediately usually cannot read its config: {}", immediately usually cannot read its config: {}",
command_line("sc.exe", &["start", WINDOWS_SERVICE]), crate::util::command_line("sc.exe", &["start", WINDOWS_SERVICE]),
start.status.code().unwrap_or(-1), start.status.code().unwrap_or(-1),
config.display() config.display()
); );
@@ -798,6 +800,16 @@ mod tests {
// The write grant belongs to the database directory, which is not always the config's. // The write grant belongs to the database directory, which is not always the config's.
assert!(steps.contains("/var/lib/runicgateway'"), "{steps}"); assert!(steps.contains("/var/lib/runicgateway'"), "{steps}");
} }
#[cfg(not(windows))]
{
assert!(steps.contains("systemctl enable --now"), "{steps}");
assert!(
steps.contains("ExecStart=/usr/bin/runicgateway-link"),
"{steps}"
);
// Non-systemd hosts get the requirements, not just a unit they cannot use.
assert!(steps.contains("without systemd"), "{steps}");
}
} }
#[test] #[test]
@@ -826,16 +838,6 @@ mod tests {
assert_eq!(protected, unprotected); assert_eq!(protected, unprotected);
assert!(protected.contains("chown runicgateway"), "{protected}"); assert!(protected.contains("chown runicgateway"), "{protected}");
} }
#[cfg(not(windows))]
{
assert!(steps.contains("systemctl enable --now"), "{steps}");
assert!(
steps.contains("ExecStart=/usr/bin/runicgateway-link"),
"{steps}"
);
// Non-systemd hosts get the requirements, not just a unit they cannot use.
assert!(steps.contains("without systemd"), "{steps}");
}
} }
#[test] #[test]