From 027efa3f8386dcae14ebfacaac748d7d3213959a Mon Sep 17 00:00:00 2001 From: theMZet Date: Sat, 30 May 2026 00:41:44 +0200 Subject: [PATCH] feat: sync subcommand --- src/main.rs | 21 +++++++++++++++++++-- src/package_manager.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 70efa7d..e20667f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,7 @@ mod world; use error::*; use crate::{ - package_manager::{get_system_state, get_unneeded_packages, remove_packages}, + package_manager::{get_system_state, get_unneeded_packages, remove_packages, update_packages}, world::{World, get_world_location}, }; @@ -99,7 +99,24 @@ fn main() -> Result<()> { }; match args.command { - Commands::Sync => todo!(), + Commands::Sync => { + let world = World::load_from(world_path)?; + let world_state = world.get_packages(); + let state = get_system_state()?; + + let not_installed = { + let mut x = world_state.exclude(&state); + x.ignore = world_state.ignore.clone(); + x.exclude_ignored(); + x.get_package_list() + }; + + update_packages(¬_installed)?; + + if !args.quiet { + println!("Succesfully synchronized state with the world file!"); + } + } Commands::Export { overwrite, stdout, diff --git a/src/package_manager.rs b/src/package_manager.rs index ba334c1..a56dfca 100644 --- a/src/package_manager.rs +++ b/src/package_manager.rs @@ -62,3 +62,32 @@ pub fn remove_packages(packages: &[String], all: bool) -> Result<()> { Ok(()) } + +fn _update_packages(command: Command, packages: &[String]) -> Result<()> { + let mut command = command; + command + .arg("-Syu") + .args(packages) + .stderr(Stdio::inherit()) + .stdout(Stdio::inherit()) + .stdin(Stdio::inherit()) + .status()?; + Ok(()) +} + +#[cfg(not(any(feature = "yay", feature = "paru")))] +pub fn update_packages(packages: &[String]) -> Result<()> { + let mut command = Command::new(PRIVLAGE_ESCELATE_COMMAND); + command.arg("pacman"); + _update_packages(command, packages) +} + +#[cfg(feature = "yay")] +pub fn update_packages(packages: &[String]) -> Result<()> { + _update_packages(Command::new("yay"), packages) +} + +#[cfg(feature = "paru")] +pub fn update_packages(packages: &[String]) -> Result<()> { + _update_packages(Command::new("paru"), packages) +}