Skip to content
Snippets Groups Projects
Commit 50b981a4 authored by Adam Vandenberg's avatar Adam Vandenberg
Browse files

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.
parent c9db120e
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment