@@ -42,6 +42,7 @@ require 'fileutils'
4242require 'json'
4343require 'pp'
4444require 'rbconfig'
45+ require 'rexml/document'
4546
4647require_relative 'lib/ruby_version'
4748
@@ -53,6 +54,8 @@ def show_help_message
5354end
5455
5556URI_BASE = 'https://cache.ruby-lang.org/pub/ruby/'
57+ S3_BUCKET_BASE = 'https://s3.amazonaws.com/ftp.r-l.o/'
58+ S3_PREFIX = 'pub/ruby/'
5659
5760# 'rake sync' checks the tarballs in the directories after RUBY_EOL_VERSION.
5861# https://www.ruby-lang.org/en/downloads/branches/
@@ -108,33 +111,27 @@ class RubySource
108111 result = RubySource ::TABLE . map { |h |
109112 h [ :dir ]
110113 } . uniq
111- case URI_BASE
112- when /\A (http:|https:)/
113- index = URI ( URI_BASE ) . read
114- lst = [ ]
115- index . scan ( %r{href="(?:/pub/ruby/)?(\d \. \d )/"} ) {
114+ uri = "#{ S3_BUCKET_BASE } ?list-type=2&prefix=#{ S3_PREFIX } &delimiter=/"
115+ xml = URI ( uri ) . read
116+ doc = REXML ::Document . new ( xml )
117+ lst = [ ]
118+ doc . elements . each ( 'ListBucketResult/CommonPrefixes/Prefix' ) { |e |
119+ prefix = e . text # e.g. "pub/ruby/3.4/"
120+ if %r{\A pub/ruby/(\d \. \d )/\z } =~ prefix
116121 lst << $1
117- }
118- else
119- raise "unexpected URI_BASE scheme: #{ URI_BASE } (http/https required)"
120- end
122+ end
123+ }
121124 lst . each { |n |
122125 next if result . include? n
123- #puts "New directory found: #{n}"
124126 result << n
125127 }
126- #result.map! {|n| uri = URI_BASE + n + "/" }
127- #puts result
128128 result
129129 end
130130
131131 def self . reldirs_after_eol
132132 reldirs . reject { |n | ( vercmp_key ( n ) <=> vercmp_key ( RUBY_EOL_VERSION ) ) <= 0 }
133133 end
134134
135- def self . uris_after_eol
136- reldirs_after_eol . map { |n | URI_BASE + n + "/" }
137- end
138135
139136 def self . version_lookup ( version )
140137 TABLE . each { |h |
@@ -623,12 +620,15 @@ RubySource::TABLE.each {|h|
623620 end
624621}
625622
626- def extract_entries ( index_html )
623+ def extract_entries_from_s3 ( reldir )
627624 hs = [ ]
628- index_html . scan ( /<a href="(.*?)">/ ) {
629- uri = ( index_html . base_uri + $1) . to_s
630- next unless uri . start_with? URI_BASE
631- relpath = uri [ URI_BASE . length ..-1 ]
625+ prefix = "#{ S3_PREFIX } #{ reldir } /"
626+ uri = "#{ S3_BUCKET_BASE } ?list-type=2&prefix=#{ prefix } "
627+ xml = URI ( uri ) . read
628+ doc = REXML ::Document . new ( xml )
629+ doc . elements . each ( 'ListBucketResult/Contents/Key' ) { |e |
630+ key = e . text # e.g. "pub/ruby/3.4/ruby-3.4.9.tar.xz"
631+ relpath = key . sub ( /\A pub\/ ruby\/ / , '' )
632632 next if relpath . empty?
633633 h = make_entry ( relpath )
634634 next if h [ :suffix ] . empty?
@@ -669,11 +669,10 @@ def update_versions(relpath_list)
669669end
670670
671671task 'sync' do
672- uris = RubySource . uris_after_eol
673- uris . reverse_each { |uri |
674- puts uri
675- index_html = URI ( uri ) . read
676- hs = extract_entries ( index_html )
672+ reldirs = RubySource . reldirs_after_eol
673+ reldirs . reverse_each { |reldir |
674+ puts "#{ S3_BUCKET_BASE } ?list-type=2&prefix=#{ S3_PREFIX } #{ reldir } /"
675+ hs = extract_entries_from_s3 ( reldir )
677676 hs = filter_suffix ( hs )
678677 relpath_list = hs . map { |h | h [ :relpath ] }
679678 update_versions relpath_list
0 commit comments