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.
This commit is contained in:
Adam Vandenberg 2009-09-21 16:12:01 -07:00
parent c9db120edf
commit 50b981a469

View File

@ -139,8 +139,29 @@ end
def clean f def clean f
Cleaner.new 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 end