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.
This commit is contained in:
parent
36bb590e82
commit
e60ea7bd20
@ -141,25 +141,19 @@ def clean f
|
|||||||
Cleaner.new f
|
Cleaner.new f
|
||||||
|
|
||||||
# Hunt for empty folders and nuke them unless they are
|
# 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
|
# We want post-order traversal, so put the dirs in a stack
|
||||||
# and then pop them off later.
|
# and then pop them off later.
|
||||||
paths = Array.new
|
paths = []
|
||||||
Find.find(f.prefix) do |path|
|
f.prefix.find do |path|
|
||||||
if FileTest.directory? path
|
paths << path if path.directory?
|
||||||
paths.push path
|
|
||||||
end
|
|
||||||
next
|
|
||||||
end
|
end
|
||||||
|
|
||||||
until paths.empty? do
|
until paths.empty? do
|
||||||
path = paths.pop
|
d = paths.pop
|
||||||
next if f.skip_clean? Pathname.new(path)
|
if d.children.empty? and not f.skip_clean? d
|
||||||
entries = Dir.entries(path) - [".", ".."]
|
puts "rmdir: #{d} (empty)" if ARGV.verbose?
|
||||||
if entries.empty?
|
d.rmdir
|
||||||
puts "Removing empty #{path}"
|
|
||||||
Dir.rmdir path
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user