aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib
diff options
context:
space:
mode:
authorMarkus Reiter2016-08-23 01:43:03 +0200
committerMarkus Reiter2016-08-23 01:43:03 +0200
commit3e81934b8f424b9ec4f0c16962f2d683b66a6ff8 (patch)
tree244f0adb5dc6a1d8e1675bd22b1f6f9ad0ae0268 /Library/Homebrew/cask/lib
parenta70c60baeacf6ec6835fb0112fb5d1c9dd51012a (diff)
downloadbrew-3e81934b8f424b9ec4f0c16962f2d683b66a6ff8.tar.bz2
Allow per-cask `cleanup`.
Diffstat (limited to 'Library/Homebrew/cask/lib')
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/cleanup.rb30
1 files changed, 25 insertions, 5 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb b/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb
index b098a243d..4115d26fc 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb
@@ -10,8 +10,12 @@ class Hbc::CLI::Cleanup < Hbc::CLI::Base
true
end
- def self.run(*_ignored)
- default.cleanup!
+ def self.run(*args)
+ if args.empty?
+ default.cleanup!
+ else
+ default.cleanup(args)
+ end
end
def self.default
@@ -25,7 +29,11 @@ class Hbc::CLI::Cleanup < Hbc::CLI::Base
end
def cleanup!
- remove_all_cache_files
+ remove_cache_files
+ end
+
+ def cleanup(tokens)
+ remove_cache_files(*tokens)
end
def cache_files
@@ -55,11 +63,23 @@ class Hbc::CLI::Cleanup < Hbc::CLI::Base
Hbc::Utils.size_in_bytes(cache_files)
end
- def remove_all_cache_files
+ def remove_cache_files(*tokens)
message = "Removing cached downloads"
+ message.concat " for #{tokens.join(', ')}" unless tokens.empty?
message.concat " older than #{OUTDATED_DAYS} days old" if outdated_only
ohai message
- delete_paths(cache_files)
+
+ deletable_cache_files = if tokens.empty?
+ cache_files
+ else
+ start_withs = tokens.map { |token| "#{token}--" }
+
+ cache_files.select { |path|
+ path.basename.to_s.start_with?(*start_withs)
+ }
+ end
+
+ delete_paths(deletable_cache_files)
end
def delete_paths(paths)