mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Fix prune
Don't prune everything! Also added count puts
This commit is contained in:
parent
02cef8a36e
commit
985030ad82
@ -6,14 +6,27 @@ require 'pathname'
|
|||||||
$root = Pathname.new(__FILE__).realpath.dirname.parent.parent
|
$root = Pathname.new(__FILE__).realpath.dirname.parent.parent
|
||||||
|
|
||||||
def prune
|
def prune
|
||||||
|
n=0
|
||||||
|
dirs=Array.new
|
||||||
$root.find do |path|
|
$root.find do |path|
|
||||||
if path.directory?
|
if path.directory?
|
||||||
name=path.basename
|
name=path.relative_path_from($root).to_s
|
||||||
Find.prune if name == 'Cellar' or name == 'Formula'
|
if name == '.git' or name == 'Cellar' or name == 'Formula'
|
||||||
|
Find.prune
|
||||||
|
else
|
||||||
|
dirs<<path
|
||||||
|
end
|
||||||
elsif path.symlink?
|
elsif path.symlink?
|
||||||
path.unlink unless path.readlink.exist?
|
resolved_path=path.dirname+path.readlink
|
||||||
|
unless resolved_path.exist?
|
||||||
|
path.unlink
|
||||||
|
n+=1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# entries lists '.' and '..' so 2 is minimum basically
|
||||||
|
dirs.sort.reverse_each { |d| d.rmdir if d.children.length == 0 }
|
||||||
|
return n
|
||||||
end
|
end
|
||||||
|
|
||||||
case ARGV[0]
|
case ARGV[0]
|
||||||
@ -48,12 +61,16 @@ case ARGV[0]
|
|||||||
to.mkpath unless to.exist?
|
to.mkpath unless to.exist?
|
||||||
elsif from.file?
|
elsif from.file?
|
||||||
tod=to.dirname
|
tod=to.dirname
|
||||||
Dir.chdir(tod) { `ln -s "#{from.relative_path_from tod}"` }
|
Dir.chdir(tod) do
|
||||||
|
`ln -sf "#{from.relative_path_from tod}"`
|
||||||
|
n+=1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
puts "Created #{n} links"
|
||||||
|
|
||||||
when 'prune', 'pasteurize' then
|
when 'prune', 'pasteurize' then
|
||||||
prune
|
puts "Pruned #{prune} files"
|
||||||
|
|
||||||
else
|
else
|
||||||
puts "usage: #{$0} [prune] [ln path] [install pkg]"
|
puts "usage: #{$0} [prune] [ln path] [install pkg]"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user