aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Nagel2013-08-09 21:09:48 -0500
committerJack Nagel2013-08-10 19:02:00 -0500
commit99976efeed53b17d7cf331fbdfe7710bf8a80cd2 (patch)
tree7897d13241d645cb881136a79dba0230eb507b83
parent8508bdf98582805194c4e52a8d5531d5e77975d0 (diff)
downloadhomebrew-99976efeed53b17d7cf331fbdfe7710bf8a80cd2.tar.bz2
Make usage of ObserverPathnameExtension more obvious
Remove use of globals. Closes #21795.
-rw-r--r--Library/Homebrew/cmd/prune.rb15
-rw-r--r--Library/Homebrew/extend/pathname.rb26
-rw-r--r--Library/Homebrew/keg.rb11
3 files changed, 30 insertions, 22 deletions
diff --git a/Library/Homebrew/cmd/prune.rb b/Library/Homebrew/cmd/prune.rb
index 46c74a305..a6ffc2b84 100644
--- a/Library/Homebrew/cmd/prune.rb
+++ b/Library/Homebrew/cmd/prune.rb
@@ -2,12 +2,9 @@ require 'keg'
require 'cmd/tap'
module Homebrew extend self
- # $n and $d are used by the ObserverPathnameExtension to keep track of
- # certain filesystem actions.
-
def prune
- $n = 0
- $d = 0
+ ObserverPathnameExtension.reset_counts!
+
dirs = []
Keg::PRUNEABLE_DIRECTORIES.select(&:directory?).each do |dir|
@@ -41,11 +38,13 @@ module Homebrew extend self
repair_taps unless ARGV.dry_run?
- if $n == 0 && $d == 0
+ n, d = ObserverPathnameExtension.counts
+
+ if ObserverPathnameExtension.total.zero?
puts "Nothing pruned" if ARGV.verbose?
else
- print "Pruned #{$n} symbolic links "
- print "and #{$d} directories " if $d > 0
+ print "Pruned #{n} symbolic links "
+ print "and #{d} directories " if d > 0
puts "from #{HOMEBREW_PREFIX}"
end unless ARGV.dry_run?
end
diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb
index b143b9225..fc2df4407 100644
--- a/Library/Homebrew/extend/pathname.rb
+++ b/Library/Homebrew/extend/pathname.rb
@@ -433,21 +433,36 @@ class Pathname
end
end
-# sets $n and $d so you can observe creation of stuff
module ObserverPathnameExtension
+ class << self
+ attr_accessor :n, :d
+
+ def reset_counts!
+ @n = @d = 0
+ end
+
+ def total
+ n + d
+ end
+
+ def counts
+ [n, d]
+ end
+ end
+
def unlink
super
puts "rm #{to_s}" if ARGV.verbose?
- $n+=1
+ ObserverPathnameExtension.n += 1
end
def rmdir
super
puts "rmdir #{to_s}" if ARGV.verbose?
- $d+=1
+ ObserverPathnameExtension.d += 1
end
def make_relative_symlink src
super
- $n+=1
+ ObserverPathnameExtension.n += 1
end
def install_info
super
@@ -458,6 +473,3 @@ module ObserverPathnameExtension
puts "uninfo #{to_s}" if ARGV.verbose?
end
end
-
-$n=0
-$d=0
diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb
index 6218668d6..4791255d1 100644
--- a/Library/Homebrew/keg.rb
+++ b/Library/Homebrew/keg.rb
@@ -33,9 +33,7 @@ class Keg < Pathname
end
def unlink
- # these are used by the ObserverPathnameExtension to count the number
- # of files and directories linked
- $n=$d=0
+ ObserverPathnameExtension.reset_counts!
dirs = []
@@ -62,7 +60,7 @@ class Keg < Pathname
dirs.reverse_each(&:rmdir_if_possible)
- $n+$d
+ ObserverPathnameExtension.total
end
def fname
@@ -108,8 +106,7 @@ class Keg < Pathname
def link mode=OpenStruct.new
raise "Cannot link #{fname}\nAnother version is already linked: #{linked_keg_record.realpath}" if linked_keg_record.directory?
- $n=0
- $d=0
+ ObserverPathnameExtension.reset_counts!
share_mkpaths = %w[aclocal doc info locale man]
share_mkpaths.concat((1..8).map { |i| "man/man#{i}" })
@@ -175,7 +172,7 @@ class Keg < Pathname
optlink
end
- return $n + $d
+ ObserverPathnameExtension.total
rescue Exception
opoo "Could not link #{fname}. Unlinking..."
unlink