aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorAdam Vandenberg2012-04-29 11:51:04 -0700
committerAdam Vandenberg2012-05-02 19:57:33 -0700
commit93f2244cf8ff6285c310354d1ade866cf3ef7d37 (patch)
treecbee9bb3599ad614736e55cde907f91f5205bdc9 /Library
parent52732da91bb78e158f108c66239a8a57bba6f7a9 (diff)
downloadhomebrew-93f2244cf8ff6285c310354d1ade866cf3ef7d37.tar.bz2
patches - support detection of compression types
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/formula.rb9
-rw-r--r--Library/Homebrew/patches.rb73
2 files changed, 56 insertions, 26 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 86985b7b9..ed2cec904 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -525,17 +525,16 @@ private
patch_list = Patches.new(patches)
return if patch_list.empty?
- unless patch_list.external_curl_args.empty?
+ if patch_list.external_patches?
ohai "Downloading patches"
- # downloading all at once is much more efficient, especially for FTP
- curl(*patch_list.external_curl_args)
+ patch_list.download!
end
ohai "Patching"
patch_list.each do |p|
case p.compression
- when :gzip then safe_system "/usr/bin/gunzip", p.download_filename
- when :bzip2 then safe_system "/usr/bin/bunzip2", p.download_filename
+ when :gzip then safe_system "/usr/bin/gunzip", p.compressed_filename
+ when :bzip2 then safe_system "/usr/bin/bunzip2", p.compressed_filename
end
# -f means don't prompt the user if there are errors; just exit with non-zero status
safe_system '/usr/bin/patch', '-f', *(p.patch_args)
diff --git a/Library/Homebrew/patches.rb b/Library/Homebrew/patches.rb
index e3cab1ed9..a671782bc 100644
--- a/Library/Homebrew/patches.rb
+++ b/Library/Homebrew/patches.rb
@@ -15,9 +15,8 @@ class Patches
end
end
- # Collects the urls and output names of all external patches
- def external_curl_args
- @patches.select{|p| p.external?}.collect{|p| p.curl_args}.flatten
+ def external_patches?
+ not external_curl_args.empty?
end
def each(&blk)
@@ -27,8 +26,26 @@ class Patches
@patches.empty?
end
+ def download!
+ return unless external_patches?
+
+ # downloading all at once is much more efficient, especially for FTP
+ curl(*external_curl_args)
+
+ external_patches.each{|p| p.stage!}
+ end
+
private
+ def external_patches
+ @patches.select{|p| p.external?}
+ end
+
+ # Collects the urls and output names of all external patches
+ def external_curl_args
+ external_patches.collect{|p| p.curl_args}.flatten
+ end
+
def normalize_patches patches
if patches.kind_of? Hash
patches
@@ -40,29 +57,21 @@ private
end
class Patch
+ # Used by formula to unpack after downloading
attr_reader :compression
- attr_reader :url
- attr_reader :download_filename
+ attr_reader :compressed_filename
def initialize patch_p, filename, url
@patch_p = patch_p
@patch_filename = filename
- @compression = false
+ @compressed_filename = nil
+ @compression = nil
@url = nil
if url.kind_of? File # true when DATA is passed
write_data url
elsif looks_like_url(url)
- @download_filename = @patch_filename
- @url = url # Save URL
- case @url
- when /\.gz$/
- @compression = :gzip
- @download_filename += '.gz'
- when /\.bz2$/
- @compression = :bzip2
- @download_filename += '.bz2'
- end
+ @url = url # Save URL to mark this as an external patch
else
# it's a file on the local filesystem
# use URL as the filename for patch
@@ -70,12 +79,22 @@ class Patch
end
end
- def external?
- !!@url
+ # rename the downloaded file to take compression into account
+ def stage!
+ return unless external?
+ detect_compression!
+ case @compression
+ when :gzip
+ @compressed_filename = @patch_filename + '.gz'
+ FileUtils.mv @patch_filename, @compressed_filename
+ when :bzip2
+ @compressed_filename = @patch_filename + '.bz2'
+ FileUtils.mv @patch_filename, @compressed_filename
+ end
end
- def compressed?
- !!@compression
+ def external?
+ not @url.nil?
end
def patch_args
@@ -83,11 +102,23 @@ class Patch
end
def curl_args
- [@url, '-o', @download_filename]
+ [@url, '-o', @patch_filename]
end
private
+ # Detect compression type from the downloaded patch.
+ def detect_compression!
+ # If nil we have not tried to detect yet
+ if @compression.nil?
+ path = Pathname.new(@patch_filename)
+ if path.exist?
+ @compression = path.compression_type
+ @compression ||= :none # If nil, convert to :none
+ end
+ end
+ end
+
# Write the given file object (DATA) out to a local file for patch
def write_data f
pn = Pathname.new @patch_filename