aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorAdam Vandenberg2010-01-16 17:54:14 -0800
committerAdam Vandenberg2010-02-01 12:50:16 -0800
commit6d06b9a1796383e9daf40670a0995da6eefd330b (patch)
tree5458a4785387bf5a94fde4d09274560612362b43 /Library
parent43dc7c964511864e10e10c0981f6716a3f7950fd (diff)
downloadbrew-6d06b9a1796383e9daf40670a0995da6eefd330b.tar.bz2
Create Download Strategy sooner in formula install code.
* Instantiate DownloadStrategy instance when creating a formula. * Rename CurlDownloadStrategy member to clarify what it is for. * Generate downloaded tarball name in initialize.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/download_strategy.rb34
-rw-r--r--Library/Homebrew/formula.rb13
2 files changed, 28 insertions, 19 deletions
diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb
index 68cb0bf16..c15ea4bd6 100644
--- a/Library/Homebrew/download_strategy.rb
+++ b/Library/Homebrew/download_strategy.rb
@@ -53,42 +53,46 @@ class AbstractDownloadStrategy
end
class CurlDownloadStrategy <AbstractDownloadStrategy
- def fetch
- ohai "Downloading #{@url}"
+ def initialize url, name, version, specs
+ super
if @unique_token
- @dl=HOMEBREW_CACHE+(@unique_token+ext)
+ @tarball_path=HOMEBREW_CACHE+(@unique_token+ext)
else
- @dl=HOMEBREW_CACHE+File.basename(@url)
+ @tarball_path=HOMEBREW_CACHE+File.basename(@url)
end
- unless @dl.exist?
+ end
+
+ def fetch
+ ohai "Downloading #{@url}"
+ unless @tarball_path.exist?
begin
- curl @url, '-o', @dl
+ curl @url, '-o', @tarball_path
rescue Exception
- ignore_interrupts { @dl.unlink if @dl.exist? }
+ ignore_interrupts { @tarball_path.unlink if @tarball_path.exist? }
raise
end
else
puts "File already downloaded and cached to #{HOMEBREW_CACHE}"
end
- return @dl # thus performs checksum verification
+ return @tarball_path # thus performs checksum verification
end
def stage
- # magic numbers stolen from /usr/share/file/magic/
- if @dl.extname == '.jar'
+ if @tarball_path.extname == '.jar'
magic_bytes = nil
else
# get the first four bytes
- File.open(@dl) { |f| magic_bytes = f.read(4) }
+ File.open(@tarball_path) { |f| magic_bytes = f.read(4) }
end
+ # magic numbers stolen from /usr/share/file/magic/
case magic_bytes
when /^PK\003\004/ # .zip archive
- quiet_safe_system '/usr/bin/unzip', {:quiet_flag => '-qq'}, @dl
+ quiet_safe_system '/usr/bin/unzip', {:quiet_flag => '-qq'}, @tarball_path
chdir
when /^\037\213/, /^BZh/, /^\037\235/ # gzip/bz2/compress compressed
# TODO check if it's really a tar archive
- safe_system '/usr/bin/tar', 'xf', @dl
+ safe_system '/usr/bin/tar', 'xf', @tarball_path
chdir
else
# we are assuming it is not an archive, use original filename
@@ -98,7 +102,7 @@ class CurlDownloadStrategy <AbstractDownloadStrategy
# behaviour, just open an issue at github
# We also do this for jar files, as they are in fact zip files, but
# we don't want to unzip them
- FileUtils.mv @dl, File.basename(@url)
+ FileUtils.mv @tarball_path, File.basename(@url)
end
end
@@ -130,7 +134,7 @@ end
# Useful for installing jars.
class NoUnzipCurlDownloadStrategy <CurlDownloadStrategy
def stage
- FileUtils.mv @dl, File.basename(@url)
+ FileUtils.mv @tarball_path, File.basename(@url)
end
end
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 963fec6d6..9485553cf 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -112,6 +112,8 @@ class Formula
CHECKSUM_TYPES.each do |type|
set_instance_variable type
end
+
+ @downloader=download_strategy.new url, name, version, specs
end
# if the dir is there, but it's empty we consider it not installed
@@ -365,12 +367,15 @@ private
end
def stage
- ds=download_strategy.new url, name, version, specs
HOMEBREW_CACHE.mkpath
- dl=ds.fetch
- verify_download_integrity dl if dl.kind_of? Pathname
+
+ downloaded_tarball = @downloader.fetch
+ if downloaded_tarball.kind_of? Pathname
+ verify_download_integrity downloaded_tarball
+ end
+
mktemp do
- ds.stage
+ @downloader.stage
yield
end
end