aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Nagel2015-04-07 21:14:32 -0400
committerJack Nagel2015-04-07 21:14:48 -0400
commit3587dc441e0c7f649dbda67a12e4b4c87e434885 (patch)
tree0891f3a0b5cfa5ccd1c30212439cf1359b344408
parent1aff1d94558e49bccfa8db4b8c4d31e244d8fd07 (diff)
downloadbrew-3587dc441e0c7f649dbda67a12e4b4c87e434885.tar.bz2
Remove duplication from cleanup methods
-rw-r--r--Library/Homebrew/cmd/cleanup.rb24
1 files changed, 7 insertions, 17 deletions
diff --git a/Library/Homebrew/cmd/cleanup.rb b/Library/Homebrew/cmd/cleanup.rb
index b4d9658d7..e0f31d797 100644
--- a/Library/Homebrew/cmd/cleanup.rb
+++ b/Library/Homebrew/cmd/cleanup.rb
@@ -25,14 +25,7 @@ module Homebrew
return unless HOMEBREW_LOGS.directory?
time = Time.now - 2 * 7 * 24 * 60 * 60 # two weeks
HOMEBREW_LOGS.subdirs.each do |dir|
- if dir.mtime < time
- if ARGV.dry_run?
- puts "Would remove: #{dir}"
- else
- puts "Removing: #{dir}..."
- dir.rmtree
- end
- end
+ cleanup_path(dir) { dir.rmtree } if dir.mtime < time
end
end
@@ -66,11 +59,8 @@ module Homebrew
def cleanup_keg keg
if keg.linked?
opoo "Skipping (old) #{keg} due to it being linked"
- elsif ARGV.dry_run?
- puts "Would remove: #{keg} (#{keg.abv})"
else
- puts "Removing: #{keg}... (#{keg.abv})"
- keg.uninstall
+ cleanup_path(keg) { keg.uninstall }
end
end
@@ -87,17 +77,17 @@ module Homebrew
end
if f.version > version || ARGV.switch?('s') && !f.installed? || bottle_file_outdated?(f, file)
- cleanup_cached_file(file)
+ cleanup_path(file) { file.unlink }
end
end
end
- def cleanup_cached_file file
+ def cleanup_path(path)
if ARGV.dry_run?
- puts "Would remove: #{file} (#{file.abv})"
+ puts "Would remove: #{path} (#{path.abv})"
else
- puts "Removing: #{file}... (#{file.abv})"
- file.unlink
+ puts "Removing: #{path}... (#{path.abv})"
+ yield
end
end