diff options
| author | Adam Vandenberg | 2009-09-21 16:12:01 -0700 |
|---|---|---|
| committer | Adam Vandenberg | 2009-09-21 16:12:01 -0700 |
| commit | cf0e5439f10cc63a80f628284c7c27f3491b33a6 (patch) | |
| tree | d7a9378963c08fef66f63dec4c7510afb8d5e9b3 /Library | |
| parent | f9fb44d489921bd502200753377eed719d013057 (diff) | |
| download | homebrew-cf0e5439f10cc63a80f628284c7c27f3491b33a6.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.rb | 25 |
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 |
