From e60ea7bd2099873737c33c50bf65c2df908294b7 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Tue, 22 Sep 2009 11:38:22 +0100 Subject: [PATCH] Clean up the empty dir cleaner a little Using more Pathname methods. Only show text if verbose mode is on, as is typical for the rest of our install output. TODO: would be nice if we knew you were a dev and automatically enabled verbose mode perhaps. --- Library/Homebrew/brew.h.rb | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/Library/Homebrew/brew.h.rb b/Library/Homebrew/brew.h.rb index edfb15bed3..0ec3e2c002 100644 --- a/Library/Homebrew/brew.h.rb +++ b/Library/Homebrew/brew.h.rb @@ -141,25 +141,19 @@ def clean f Cleaner.new f # Hunt for empty folders and nuke them unless they are - # protected in Formula.skip_clean? - + # protected by f.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 + paths = [] + f.prefix.find do |path| + paths << path if path.directory? 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 + d = paths.pop + if d.children.empty? and not f.skip_clean? d + puts "rmdir: #{d} (empty)" if ARGV.verbose? + d.rmdir end end end