From 280ef70cc8d7b76d72253dc006708c34832e9d69 Mon Sep 17 00:00:00 2001 From: Peppe289 <gsperanza204@gmail.com> Date: Mon, 6 Mar 2023 00:03:29 +0100 Subject: [PATCH] pages.rs: fix run of orphans packages This avoid "error: no targets specified (use -h for help)" when `pacman -Qtdq` is empty. `pacman -Qtdq` can be started without root, and has a return value other than 0 if it finds no packages. So if it finds packages, it succeeds and goes to the true condition that it deletes packages. Otherwise do echo. (echo doesn't require root) Signed-off-by: Peppe289 <gsperanza204@gmail.com> --- src/pages.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pages.rs b/src/pages.rs index bddd9a5..dc5eb7c 100644 --- a/src/pages.rs +++ b/src/pages.rs @@ -65,7 +65,17 @@ fn create_fixes_section() -> gtk::Box { remove_orphans_btn.connect_clicked(move |_| { // Spawn child process in separate thread. std::thread::spawn(move || { - let _ = utils::run_cmd_terminal(String::from("pacman -Rns $(pacman -Qtdq)"), true); + // check if you have orphans packages. + let status = std::process::Command::new("pacman") + .arg("-Qtdq") + .status() + .expect("Found orphans packages"); + + if status.success() { + let _ = utils::run_cmd_terminal(String::from("pacman -Rns $(pacman -Qtdq)"), true); + } else { + let _ = utils::run_cmd_terminal(String::from("echo 'Not orphans packages'"), false); + } }); }); clear_pkgcache_btn.connect_clicked(on_clear_pkgcache_btn_clicked);