aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorAdam Vandenberg2009-09-21 16:12:01 -0700
committerAdam Vandenberg2009-09-21 16:12:01 -0700
commit50b981a46959d4bb3c8aab1f653a04d688c06bd4 (patch)
tree54550cf78e4ed2f7217dce438cf7a6c6bb4fe2c4 /Library
parentc9db120edf8a046dd0e8668376f55255fd036a64 (diff)
downloadbrew-50b981a46959d4bb3c8aab1f653a04d688c06bd4.tar.bz2
Replace perl one-liner for removing empty dirs with Ruby.
Allow Formula.skip_clean? to prevent empty folders from being removed as part of the brewing cleanup process.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/brew.h.rb25
1 files changed, 23 insertions, 2 deletions
diff --git a/Library/Homebrew/brew.h.rb b/Library/Homebrew/brew.h.rb
index d02d44dc1..edfb15bed 100644
--- a/Library/Homebrew/brew.h.rb
+++ b/Library/Homebrew/brew.h.rb
@@ -139,8 +139,29 @@ end
def clean f
Cleaner.new f
- # remove empty directories TODO Rubyize!
- `perl -MFile::Find -e"finddepth(sub{rmdir},'#{f.prefix}')"`
+
+ # Hunt for empty folders and nuke them unless they are
+ # protected in Formula.skip_clean?
+
+ # We want post-order traversal, so put the dirs in a stack
+ # and then pop them off later.
+ paths = Array.new
+ Find.find(f.prefix) do |path|
+ if FileTest.directory? path
+ paths.push path
+ end
+ next
+ end
+
+ until paths.empty? do
+ path = paths.pop
+ next if f.skip_clean? Pathname.new(path)
+ entries = Dir.entries(path) - [".", ".."]
+ if entries.empty?
+ puts "Removing empty #{path}"
+ Dir.rmdir path
+ end
+ end
end