pages.rs: fix run of orphans packages (#53)

* 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>

* pages.rs: format with rustfmt

Signed-off-by: Peppe289 <gsperanza204@gmail.com>

* 👷 use msg dialog to inform user; use Exec::cmd

---------

Signed-off-by: Peppe289 <gsperanza204@gmail.com>
Co-authored-by: Vladislav Nepogodin <nepogodin.vlad@gmail.com>
This commit is contained in:
Giuseppe Speranza 2023-03-13 00:38:13 +01:00 committed by GitHub
parent 14ad98637b
commit 22a4f56832
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 1 deletions

View File

@ -65,7 +65,26 @@ fn create_fixes_section() -> gtk::Box {
remove_orphans_btn.connect_clicked(move |_| { remove_orphans_btn.connect_clicked(move |_| {
// Spawn child process in separate thread. // Spawn child process in separate thread.
std::thread::spawn(move || { std::thread::spawn(move || {
let _ = utils::run_cmd_terminal(String::from("pacman -Rns $(pacman -Qtdq)"), true); // check if you have orphans packages.
let mut orphan_pkgs = Exec::cmd("/sbin/pacman")
.arg("-Qtdq")
.stdout(Redirection::Pipe)
.capture()
.unwrap()
.stdout_str();
// get list of packages separated by space,
// and check if it's empty or not.
orphan_pkgs = orphan_pkgs.replace('\n', " ");
if orphan_pkgs.is_empty() {
let dialog = gtk::MessageDialog::builder()
.message_type(gtk::MessageType::Info)
.text("No orphan packages found!")
.build();
dialog.show();
return;
}
let _ = utils::run_cmd_terminal(format!("pacman -Rns {orphan_pkgs}"), true);
}); });
}); });
clear_pkgcache_btn.connect_clicked(on_clear_pkgcache_btn_clicked); clear_pkgcache_btn.connect_clicked(on_clear_pkgcache_btn_clicked);