Skip to main content

build_batch_install

Function build_batch_install 

Source
pub fn build_batch_install<S: BuildHasher>(
    targets: &[PackageRef],
    helper: Option<AurHelper>,
    privilege: Option<PrivilegeTool>,
    options: &InstallOptions,
    installed: Option<&HashSet<String, S>>,
) -> Result<InstallPlan>
Expand description

What: Plan a batch installation by splitting targets between pacman and an AUR helper.

Inputs:

  • targets: Packages to install; the source field routes each to pacman or the helper.
  • helper: AUR helper to use for AUR targets. Required when any target is from the AUR.
  • privilege: When Some, the pacman command is wrapped (e.g., sudo pacman ...). AUR helper commands are never wrapped (helpers escalate internally).
  • options: Flag options; options.needed is refined per group when installed is given.
  • installed: Optional set of installed package names. When any name in a group is already installed, --needed is dropped for that group so reinstalls proceed — mirroring Pacsea’s batch reinstall detection. Pass None to use options.needed as-is.

Output:

  • Ok(InstallPlan) with grouped commands and routed names.

Details:

  • Official packages are grouped into a single pacman invocation, AUR packages into a single helper invocation (from Pacsea’s build_batch_install_command).
  • Both grouped commands inherit strict name validation and the -- operand terminator from the underlying direct builders.
  • Empty targets produces an empty plan (no error), so callers can pass through selection results unchecked.
  • arch-toolkit never executes the plan; run the commands with spec.to_command() or display them with spec.to_shell_string() (dry run).

§Errors

  • ArchToolkitError::InvalidInput when AUR targets are present but helper is None.
  • ArchToolkitError::InvalidPackageName when a target name fails validation.

§Example

use arch_toolkit::install::build_batch_install;
use arch_toolkit::types::install::{AurHelper, InstallOptions, PrivilegeTool};
use arch_toolkit::{PackageRef, PackageSource};

let targets = vec![
    PackageRef::official("ripgrep", "14.0.0", "extra", "x86_64"),
    PackageRef::aur("yay-bin", "12.0.0"),
];
let plan = build_batch_install(
    &targets,
    Some(AurHelper::Paru),
    Some(PrivilegeTool::Sudo),
    &InstallOptions::default(),
    None::<&std::collections::HashSet<String>>,
)?;
assert_eq!(plan.commands.len(), 2);
assert_eq!(
    plan.commands[0].to_shell_string(),
    "sudo pacman -S --needed --noconfirm -- ripgrep"
);
assert_eq!(
    plan.commands[1].to_shell_string(),
    "paru -S --aur --needed --noconfirm -- yay-bin"
);