From 7e5eb87b7d5c2d17548923a3617f98dd6561eb87 Mon Sep 17 00:00:00 2001 From: Nikolai Hellwig Date: Sat, 17 Nov 2018 19:09:46 +0100 Subject: [PATCH] Adding a new flag for cleaning up old resources (#90) * Adding a new flag to topgrade called "cleanup" If you are using applications like homebrew they may keep a history of packages downloaded. Especially the bigger your number of installed packages for homebrew grows the bigger those directories get. This can quickly add up to a couple of GBs. If this flag is set then the homebrew part also calls "brew cleanup" for cleaning up old resources. Of course this can be add to other calls as well if supported. * Updating readme for new cleanup flag --- README.md | 1 + src/config.rs | 3 +++ src/main.rs | 2 +- src/unix.rs | 5 ++++- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 53394972..d34ce7b8 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ Just run `topgrade`. It will run the following steps: ## Flags * `-t/--tmux` - Topgrade will launch itself in a new tmux session. This flag has no effect if Topgrade already runs inside tmux. This is useful when using topgrade on remote systems. +* `-c/--cleanup` - Topgrade will instruct package managers to remove old or unused files * `-n/--dry-run` - Print what should be run. * `--no-system` - Skip the system upgrade phase. * `--no-git-repos` - Don't pull custom git repositories. diff --git a/src/config.rs b/src/config.rs index 33531b1f..73896386 100644 --- a/src/config.rs +++ b/src/config.rs @@ -51,6 +51,9 @@ pub struct Opt { #[structopt(short = "t", long = "tmux", help = "Run inside tmux")] pub run_in_tmux: bool, + #[structopt(short = "c", long = "cleanup", help = "Cleanup temporary or old files")] + pub cleanup: bool, + #[structopt(long = "no-system", help = "Don't perform system upgrade")] pub no_system: bool, diff --git a/src/main.rs b/src/main.rs index bc41d3cf..39fbf3a0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -240,7 +240,7 @@ fn run() -> Result<(), Error> { #[cfg(unix)] report.push_result(execute( - |terminal| unix::run_homebrew(terminal, opt.dry_run), + |terminal| unix::run_homebrew(terminal, opt.cleanup, opt.dry_run), &mut execution_context, )?); #[cfg(target_os = "freebsd")] diff --git a/src/unix.rs b/src/unix.rs index fa25e969..e1754049 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -52,13 +52,16 @@ pub fn run_fisher(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) } #[must_use] -pub fn run_homebrew(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { +pub fn run_homebrew(terminal: &mut Terminal, cleanup: bool, dry_run: bool) -> Option<(&'static str, bool)> { if let Some(brew) = which("brew") { terminal.print_separator("Brew"); let inner = || -> Result<(), Error> { Executor::new(&brew, dry_run).arg("update").spawn()?.wait()?.check()?; Executor::new(&brew, dry_run).arg("upgrade").spawn()?.wait()?.check()?; + if cleanup { + Executor::new(&brew, dry_run).arg("cleanup").spawn()?.wait()?.check()?; + } Ok(()) };