From a9c534a2a298c558da85161c96139abc1bdedad5 Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Tue, 2 Oct 2018 14:30:10 +0300 Subject: [PATCH] Separate Flatpak user from Flatpak global (fix #67) --- src/linux.rs | 34 ++++++++++++++++++++++++++++++---- src/main.rs | 6 +++++- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/linux.rs b/src/linux.rs index 371d349b..5fb267f3 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -220,20 +220,46 @@ pub fn run_fwupdmgr(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static } #[must_use] -pub fn run_flatpak(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { +pub fn flatpak_user_update(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { if let Some(flatpak) = which("flatpak") { - terminal.print_separator("Flatpak"); + terminal.print_separator("Flatpak User Packages"); let success = || -> Result<(), failure::Error> { Executor::new(&flatpak, dry_run) - .args(&["update", "-y"]) + .args(&["update", "--user", "-y"]) .spawn()? .wait()? .check()?; Ok(()) }().is_ok(); - return Some(("Flatpak", success)); + return Some(("Flatpak User Packages", success)); + } + + None +} + +#[must_use] +pub fn flatpak_global_update( + sudo: &Option, + terminal: &mut Terminal, + dry_run: bool, +) -> Option<(&'static str, bool)> { + if let Some(sudo) = sudo { + if let Some(flatpak) = which("flatpak") { + terminal.print_separator("Flatpak Global Packages"); + + let success = || -> Result<(), failure::Error> { + Executor::new(&sudo, dry_run) + .args(&[flatpak.to_str().unwrap(), "update", "-y"]) + .spawn()? + .wait()? + .check()?; + Ok(()) + }().is_ok(); + + return Some(("Flatpak Global Packages", success)); + } } None diff --git a/src/main.rs b/src/main.rs index cf44d467..1fd5f795 100644 --- a/src/main.rs +++ b/src/main.rs @@ -250,7 +250,11 @@ fn run() -> Result<(), Error> { #[cfg(target_os = "linux")] { report.push_result(execute( - |terminal| linux::run_flatpak(terminal, opt.dry_run), + |terminal| linux::flatpak_user_update(terminal, opt.dry_run), + &mut terminal, + )); + report.push_result(execute( + |terminal| linux::flatpak_global_update(&sudo, terminal, opt.dry_run), &mut terminal, )); report.push_result(execute(