[DRE-commits] [librarian-puppet] 66/97: Make download of tarballs more robust

Stig Sandbeck Mathisen ssm at debian.org
Tue Mar 11 12:12:51 UTC 2014


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository librarian-puppet.

commit 386b0488cf95668f20bfa1dd3da702e86af0104d
Author: James Abley <james.abley at gmail.com>
Date:   Fri Jan 17 10:09:11 2014 +0000

    Make download of tarballs more robust
    
    Prevents 500 / 504 responses being ignored.
---
 lib/librarian/puppet/source/githubtarball.rb | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/lib/librarian/puppet/source/githubtarball.rb b/lib/librarian/puppet/source/githubtarball.rb
index a5133b6..db7a7f4 100644
--- a/lib/librarian/puppet/source/githubtarball.rb
+++ b/lib/librarian/puppet/source/githubtarball.rb
@@ -1,5 +1,6 @@
 require 'uri'
 require 'net/https'
+require 'open-uri'
 require 'json'
 
 require 'librarian/puppet/version'
@@ -98,7 +99,20 @@ module Librarian
 
             url = "https://api.github.com/repos/#{name}/tarball/#{version}"
             url << "?access_token=#{ENV['GITHUB_API_TOKEN']}" if ENV['GITHUB_API_TOKEN']
-            `curl #{url} -o #{vendored_path(name, version).to_s} -L 2>&1`
+
+            File.open(vendored_path(name, version).to_s, 'wb') do |f|
+              begin
+                debug { "Downloading <#{url}> to <#{f.path}>" }
+                open(url,
+                  "User-Agent" => "librarian-puppet v#{Librarian::Puppet::VERSION}") do |res|
+                  while buffer = res.read(8192)
+                    f.write(buffer)
+                  end
+                end
+              rescue OpenURI::HTTPError => e
+                raise e, "Error requesting <#{url}>: #{e.to_s}"
+              end
+            end
           end
 
           def clean_up_old_cached_versions(name)
@@ -107,6 +121,10 @@ module Librarian
             end
           end
 
+          def debug(*args, &block)
+            environment.logger.debug(*args, &block)
+          end
+
         private
 
           def api_call(path)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/librarian-puppet.git



More information about the Pkg-ruby-extras-commits mailing list