[前][次][番号順一覧][スレッド一覧]

ruby-changes:41557

From: duerst <ko1@a...>
Date: Sat, 23 Jan 2016 16:29:47 +0900 (JST)
Subject: [ruby-changes:41557] duerst:r53631 (trunk): * tool/downloader.rb: Fixed a logical error, improved documentation

duerst	2016-01-23 16:30:32 +0900 (Sat, 23 Jan 2016)

  New Revision: 53631

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53631

  Log:
    * tool/downloader.rb: Fixed a logical error, improved documentation

  Modified files:
    trunk/ChangeLog
    trunk/tool/downloader.rb
Index: tool/downloader.rb
===================================================================
--- tool/downloader.rb	(revision 53630)
+++ tool/downloader.rb	(revision 53631)
@@ -20,8 +20,8 @@ else https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L20
       end
     end
   end
-  # since open-uri internally checks ssl_ca_cert by File.directory?, to allow
-  # accept an array.
+  # since open-uri internally checks ssl_ca_cert using File.directory?,
+  # allow to accept an array.
   class <<File
     alias orig_directory? directory?
     def File.directory? files
@@ -49,12 +49,12 @@ class Downloader https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L49
   end
 
   class RubyGems < self
-    def self.download(name, dir = nil, ims = true, options = {})
+    def self.download(name, dir = nil, since = true, options = {})
       require 'rubygems'
       require 'rubygems/package'
       options[:ssl_ca_cert] = Dir.glob(File.expand_path("../lib/rubygems/ssl_certs/*.pem", File.dirname(__FILE__)))
       file = under(dir, name)
-      super("#{https}://rubygems.org/downloads/#{name}", file, nil, ims, options) or
+      super("#{https}://rubygems.org/downloads/#{name}", file, nil, since, options) or
         return false
       policy = Gem::Security::LowSecurity
       (policy = policy.dup).ui = Gem::SilentUI.new if policy.respond_to?(:'ui=')
@@ -104,20 +104,33 @@ class Downloader https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L104
     options
   end
 
-  # Downloader.download(url, name, [dir, [ims]])
+  # Downloader.download(url, name, [dir, [since]])
   #
   # Update a file from url if newer version is available.
   # Creates the file if the file doesn't yet exist; however, the
   # directory where the file is being created has to exist already.
-  # If +ims+ is false, always download url regardless of its last
-  # modified time.
+  # The +since+ parameter can take the following values, with associated meanings:
+  #  true ::
+  #    Take the last-modified time of the current file on disk, and only download
+  #    if the server has a file that was modified later. Download unconditionally
+  #    if we don't have the file yet. Default.
+  #  +some time value+ ::
+  #    Use this time value instead of the time of modification of the file on disk.
+  #  nil ::
+  #    Only download the file if it doesn't exist yet.
+  #  false ::
+  #    always download url regardless of whether we already have a file,
+  #    and regardless of modification times. (This is essentially just a waste of
+  #    network resources, except in the case that the file we have is somehow damaged.
+  #    Please note that using this recurringly might create or be seen as a
+  #    denial of service attack.)
   #
   # Example usage:
   #   download 'http://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt',
   #            'UnicodeData.txt', 'enc/unicode/data'
-  def self.download(url, name, dir = nil, ims = true, options = {})
+  def self.download(url, name, dir = nil, since = true, options = {})
     file = under(dir, name)
-    if ims.nil? and File.exist?(file)
+    if since.nil? and File.exist?(file)
       if $VERBOSE
         $stdout.puts "#{name} already exists"
         $stdout.flush
@@ -130,24 +143,24 @@ class Downloader https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L143
       $stdout.flush
     end
     begin
-      data = url.read(options.merge(http_options(file, ims.nil? ? true : ims)))
+      data = url.read(options.merge(http_options(file, since.nil? ? true : since)))
     rescue OpenURI::HTTPError => http_error
       if http_error.message =~ /^304 / # 304 Not Modified
         if $VERBOSE
-          $stdout.puts "not modified"
+          $stdout.puts "#{name} not modified"
           $stdout.flush
         end
         return true
       end
       raise
     rescue Timeout::Error
-      if ims.nil? and File.exist?(file)
+      if since.nil? and File.exist?(file)
         puts "Request for #{url} timed out, using old version."
         return true
       end
       raise
     rescue SocketError
-      if ims.nil? and File.exist?(file)
+      if since.nil? and File.exist?(file)
         puts "No network connection, unable to download #{url}, using old version."
         return true
       end
@@ -180,7 +193,7 @@ end https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L193
 Downloader.class_variable_set(:@@https, https.freeze)
 
 if $0 == __FILE__
-  ims = true
+  since = true
   until ARGV.empty?
     case ARGV[0]
     when '-d'
@@ -192,9 +205,9 @@ if $0 == __FILE__ https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L205
       prefix = ARGV[1]
       ARGV.shift
     when '-e'
-      ims = nil
+      since = nil
     when '-a'
-      ims = true
+      since = false
     when /\A-/
       abort "#{$0}: unknown option #{ARGV[0]}"
     else
@@ -211,10 +224,10 @@ if $0 == __FILE__ https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L224
     ARGV.shift
     ARGV.each do |name|
       name = "#{prefix}/#{File.basename(name)}" if prefix
-      dl.download(name, destdir, ims)
+      dl.download(name, destdir, since)
     end
   else
     abort "usage: #{$0} url name" unless ARGV.size == 2
-    Downloader.download(ARGV[0], ARGV[1], destdir, ims)
+    Downloader.download(ARGV[0], ARGV[1], destdir, since)
   end
 end
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53630)
+++ ChangeLog	(revision 53631)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jan 23 16:29:42 2016  Martin Duerst  <duerst@i...>
+
+	* tool/downloader.rb: Fixed a logical error, improved documentation
+
 Sat Jan 23 11:42:43 2016  Peter Suschlik  <ps@n...>
 
 	* README.md: Use SVG Travis badge over PNG for better quality and

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]