Implement cleanup for Pacman

This commit is contained in:
Roey Darwish Dror
2018-12-23 10:47:45 +02:00
parent 83b6f9ace4
commit badc6b665b

View File

@@ -63,7 +63,7 @@ impl Distribution {
print_separator("System update"); print_separator("System update");
let success = match self { let success = match self {
Distribution::Arch => upgrade_arch_linux(&sudo, dry_run), Distribution::Arch => upgrade_arch_linux(&sudo, cleanup, dry_run),
Distribution::CentOS => upgrade_redhat(&sudo, dry_run), Distribution::CentOS => upgrade_redhat(&sudo, dry_run),
Distribution::Fedora => upgrade_fedora(&sudo, dry_run), Distribution::Fedora => upgrade_fedora(&sudo, dry_run),
Distribution::Ubuntu | Distribution::Debian => upgrade_debian(&sudo, cleanup, dry_run), Distribution::Ubuntu | Distribution::Debian => upgrade_debian(&sudo, cleanup, dry_run),
@@ -103,7 +103,7 @@ pub fn show_pacnew() {
} }
} }
fn upgrade_arch_linux(sudo: &Option<PathBuf>, dry_run: bool) -> Result<(), Error> { fn upgrade_arch_linux(sudo: &Option<PathBuf>, cleanup: bool, dry_run: bool) -> Result<(), Error> {
if let Some(yay) = which("yay") { if let Some(yay) = which("yay") {
if let Some(python) = which("python") { if let Some(python) = which("python") {
if python != PathBuf::from("/usr/bin/python") { if python != PathBuf::from("/usr/bin/python") {
@@ -127,6 +127,16 @@ It's dangerous to run yay since Python based AUR packages will be installed in t
print_warning("No sudo or yay detected. Skipping system upgrade"); print_warning("No sudo or yay detected. Skipping system upgrade");
} }
if cleanup {
if let Some(sudo) = &sudo {
Executor::new(&sudo, dry_run)
.args(&["/usr/bin/pacman", "-Scc"])
.spawn()?
.wait()?
.check()?;
}
}
Ok(()) Ok(())
} }