Quote paths in shell commands

This commit is contained in:
Max Howell 2009-05-21 12:40:40 +01:00
parent 358c5c8b8a
commit 1b5d1c16ac
2 changed files with 8 additions and 8 deletions

View File

@ -14,10 +14,10 @@ case ARGV[0]
when 'ln' then when 'ln' then
abort "#{ARGV[1]} is not a directory" unless File.directory? ARGV[1] abort "#{ARGV[1]} is not a directory" unless File.directory? ARGV[1]
#TODO check is under +/ with name AND version #TODO if user specifies just name and not version dir, do latest version
#TODO you should mkdirs as you find them and symlink files otherwise #TODO you should mkdirs as you find them and symlink files otherwise
#TODO consider using hardlinks #TODO consider using hardlinks
target=Pathname.new(ARGV[1]).realpath target=Pathname.new(ARGV[1]).realpath
target.find do |from| target.find do |from|
next if from == ARGV[1] #rubysucks next if from == ARGV[1] #rubysucks
@ -28,7 +28,7 @@ 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) { `ln -s "#{from.relative_path_from tod}"` }
end end
end end
@ -43,5 +43,5 @@ case ARGV[0]
end end
else else
puts "usage: #{$0} [prune] [ln path]" puts "usage: #{$0} [prune] [ln path] [install pkg]"
end end

View File

@ -20,7 +20,7 @@ end
class Formula class Formula
require 'find' require 'find'
require 'fileutils' require 'fileutils'
# if you reimplement, assign @name, @version, @url and @md5 # if you reimplement, assign @name, @version, @url and @md5
def initialize(url, md5) def initialize(url, md5)
@name = File.basename $0, '.rb' #original script that the interpreter started @name = File.basename $0, '.rb' #original script that the interpreter started
@ -44,7 +44,7 @@ class Formula
def brew def brew
raise "@name.nil?" if @name.nil? raise "@name.nil?" if @name.nil?
raise "@version.nil?" if @version.nil? raise "@version.nil?" if @version.nil?
# disabled until the regexp makes sense :P # disabled until the regexp makes sense :P
#raise "@name does not validate to our regexp" unless /^\w+$/ =~ @name #raise "@name does not validate to our regexp" unless /^\w+$/ =~ @name
@ -86,7 +86,7 @@ class Formula
# stay in appsupport in case any odd files gets created etc. # stay in appsupport in case any odd files gets created etc.
`#{$cellar}/homebrew/brew ln #{prefix}` if prefix.exist? `#{$cellar}/homebrew/brew ln #{prefix}` if prefix.exist?
puts "#{prefix}: "+`find #{prefix} -type f | wc -l`.strip+' files, '+`du -hd0 #{prefix} | cut -d"\t" -f1`.strip+", built in #{Time.now - beginning} seconds" puts "#{prefix}: "+`find #{prefix} -type f | wc -l`.strip+' files, '+`du -hd0 #{prefix} | cut -d"\t" -f1`.strip+", built in #{Time.now - beginning} seconds"
end end
end end
@ -102,7 +102,7 @@ protected
def fetch def fetch
tgz=File.expand_path File.basename(@url) tgz=File.expand_path File.basename(@url)
unless File.exists? tgz unless File.exists? tgz
`curl -LOA "#{$agent}" "#{@url}"` `curl -LOA "#{$agent}" "#{@url}"`
raise "Download failed" unless $? == 0 raise "Download failed" unless $? == 0
end end
return tgz return tgz