Class: Gemirro::Indexer
- Inherits:
-
Gem::Indexer
- Object
- Gem::Indexer
- Gemirro::Indexer
- Defined in:
- lib/gemirro/indexer.rb
Overview
The Indexer class is responsible for downloading useful file directly on the source host, such as specs-..gz, marshal information, etc…
Instance Attribute Summary collapse
- #dest_directory ⇒ String
- #directory ⇒ String
- #files ⇒ Array
- #only_origin ⇒ Boolean
- #quick_marshal_dir ⇒ String
Instance Method Summary collapse
- #build_indicies ⇒ Object
- #download_from_source(file) ⇒ Object
-
#initialize(directory, options = {}) ⇒ Array
constructor
Create an indexer that will index the gems in
directory
. -
#install_indicies ⇒ Array
Generate indicies on the destination directory.
Constructor Details
#initialize(directory, options = {}) ⇒ Array
Create an indexer that will index the gems in directory
.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/gemirro/indexer.rb', line 33 def initialize(directory, = {}) require 'fileutils' require 'tmpdir' require 'zlib' unless defined?(Builder::XChar) fail 'Gem::Indexer requires that the XML Builder ' \ 'library be installed:' \ "\n\tgem install builder" end = { build_modern: true }.merge @build_modern = [:build_modern] @dest_directory = directory @directory = File.join(Dir.tmpdir, "gem_generate_index_#{rand(1_000_000_000)}") marshal_name = "Marshal.#{::Gem.marshal_version}" @master_index = File.join @directory, 'yaml' @marshal_index = File.join @directory, marshal_name @quick_dir = File.join @directory, 'quick' @quick_marshal_dir = File.join @quick_dir, marshal_name @quick_marshal_dir_base = File.join 'quick', marshal_name # FIX: UGH @quick_index = File.join @quick_dir, 'index' @latest_index = File.join @quick_dir, 'latest_index' @specs_index = File.join @directory, "specs.#{::Gem.marshal_version}" @latest_specs_index = File.join(@directory, "latest_specs.#{::Gem.marshal_version}") @prerelease_specs_index = File.join(@directory, "prerelease_specs.#{::Gem.marshal_version}") @dest_specs_index = File.join(@dest_directory, "specs.#{::Gem.marshal_version}") @dest_latest_specs_index = File.join(@dest_directory, "latest_specs.#{::Gem.marshal_version}") @dest_prerelease_specs_index = File.join(@dest_directory, "prerelease_specs.#{::Gem.marshal_version}") @files = [] end |
Instance Attribute Details
#dest_directory ⇒ String
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/gemirro/indexer.rb', line 19 class Indexer < ::Gem::Indexer attr_accessor(:files, :quick_marshal_dir, :directory, :dest_directory, :only_origin) ## # Create an indexer that will index the gems in +directory+. # # @param [String] directory Destination directory # @param [Hash] options Indexer options # @return [Array] ## def initialize(directory, = {}) require 'fileutils' require 'tmpdir' require 'zlib' unless defined?(Builder::XChar) fail 'Gem::Indexer requires that the XML Builder ' \ 'library be installed:' \ "\n\tgem install builder" end = { build_modern: true }.merge @build_modern = [:build_modern] @dest_directory = directory @directory = File.join(Dir.tmpdir, "gem_generate_index_#{rand(1_000_000_000)}") marshal_name = "Marshal.#{::Gem.marshal_version}" @master_index = File.join @directory, 'yaml' @marshal_index = File.join @directory, marshal_name @quick_dir = File.join @directory, 'quick' @quick_marshal_dir = File.join @quick_dir, marshal_name @quick_marshal_dir_base = File.join 'quick', marshal_name # FIX: UGH @quick_index = File.join @quick_dir, 'index' @latest_index = File.join @quick_dir, 'latest_index' @specs_index = File.join @directory, "specs.#{::Gem.marshal_version}" @latest_specs_index = File.join(@directory, "latest_specs.#{::Gem.marshal_version}") @prerelease_specs_index = File.join(@directory, "prerelease_specs.#{::Gem.marshal_version}") @dest_specs_index = File.join(@dest_directory, "specs.#{::Gem.marshal_version}") @dest_latest_specs_index = File.join(@dest_directory, "latest_specs.#{::Gem.marshal_version}") @dest_prerelease_specs_index = File.join(@dest_directory, "prerelease_specs.#{::Gem.marshal_version}") @files = [] end ## # Generate indicies on the destination directory # # @return [Array] # def install_indicies verbose = ::Gem.configuration.really_verbose Gemirro.configuration.logger .debug("Downloading index into production dir #{@dest_directory}") files = @files files.delete @quick_marshal_dir if files.include? @quick_dir if files.include?(@quick_marshal_dir) && !files.include?(@quick_dir) files.delete @quick_marshal_dir dst_name = File.join(@dest_directory, @quick_marshal_dir_base) FileUtils.mkdir_p(File.dirname(dst_name), verbose: verbose) FileUtils.rm_rf(dst_name, verbose: verbose) FileUtils.mv(@quick_marshal_dir, dst_name, verbose: verbose, force: true) end files.each do |path| file = path.sub(%r{^#{Regexp.escape @directory}/?}, '') dst_name = File.join @dest_directory, file if ["#{@specs_index}.gz", "#{@latest_specs_index}.gz", "#{@prerelease_specs_index}.gz"].include?(path) content = Marshal.load(Zlib::GzipReader.open(path).read) Zlib::GzipWriter.open("#{dst_name}.orig") do |io| io.write(Marshal.dump(content)) end unless @only_origin source_content = download_from_source(file) next if source_content.nil? source_content = Marshal.load(Zlib::GzipReader .new(StringIO .new(source_content)).read) new_content = source_content.concat(content).uniq Zlib::GzipWriter.open(dst_name) do |io| io.write(Marshal.dump(new_content)) end end else source_content = download_from_source(file) next if source_content.nil? MirrorFile.new(dst_name).write(source_content) end FileUtils.rm_rf(path) end end def download_from_source(file) source_host = Gemirro.configuration.source.host resp = Http.get("#{source_host}/#{File.basename(file)}") return unless resp.code == 200 resp.body end def build_indicies ::Gem::Specification.dirs = [] ::Gem::Specification.all = *map_gems_to_specs(gem_file_list) build_marshal_gemspecs build_modern_indicies if @build_modern compress_indicies end end |
#directory ⇒ String
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/gemirro/indexer.rb', line 19 class Indexer < ::Gem::Indexer attr_accessor(:files, :quick_marshal_dir, :directory, :dest_directory, :only_origin) ## # Create an indexer that will index the gems in +directory+. # # @param [String] directory Destination directory # @param [Hash] options Indexer options # @return [Array] ## def initialize(directory, = {}) require 'fileutils' require 'tmpdir' require 'zlib' unless defined?(Builder::XChar) fail 'Gem::Indexer requires that the XML Builder ' \ 'library be installed:' \ "\n\tgem install builder" end = { build_modern: true }.merge @build_modern = [:build_modern] @dest_directory = directory @directory = File.join(Dir.tmpdir, "gem_generate_index_#{rand(1_000_000_000)}") marshal_name = "Marshal.#{::Gem.marshal_version}" @master_index = File.join @directory, 'yaml' @marshal_index = File.join @directory, marshal_name @quick_dir = File.join @directory, 'quick' @quick_marshal_dir = File.join @quick_dir, marshal_name @quick_marshal_dir_base = File.join 'quick', marshal_name # FIX: UGH @quick_index = File.join @quick_dir, 'index' @latest_index = File.join @quick_dir, 'latest_index' @specs_index = File.join @directory, "specs.#{::Gem.marshal_version}" @latest_specs_index = File.join(@directory, "latest_specs.#{::Gem.marshal_version}") @prerelease_specs_index = File.join(@directory, "prerelease_specs.#{::Gem.marshal_version}") @dest_specs_index = File.join(@dest_directory, "specs.#{::Gem.marshal_version}") @dest_latest_specs_index = File.join(@dest_directory, "latest_specs.#{::Gem.marshal_version}") @dest_prerelease_specs_index = File.join(@dest_directory, "prerelease_specs.#{::Gem.marshal_version}") @files = [] end ## # Generate indicies on the destination directory # # @return [Array] # def install_indicies verbose = ::Gem.configuration.really_verbose Gemirro.configuration.logger .debug("Downloading index into production dir #{@dest_directory}") files = @files files.delete @quick_marshal_dir if files.include? @quick_dir if files.include?(@quick_marshal_dir) && !files.include?(@quick_dir) files.delete @quick_marshal_dir dst_name = File.join(@dest_directory, @quick_marshal_dir_base) FileUtils.mkdir_p(File.dirname(dst_name), verbose: verbose) FileUtils.rm_rf(dst_name, verbose: verbose) FileUtils.mv(@quick_marshal_dir, dst_name, verbose: verbose, force: true) end files.each do |path| file = path.sub(%r{^#{Regexp.escape @directory}/?}, '') dst_name = File.join @dest_directory, file if ["#{@specs_index}.gz", "#{@latest_specs_index}.gz", "#{@prerelease_specs_index}.gz"].include?(path) content = Marshal.load(Zlib::GzipReader.open(path).read) Zlib::GzipWriter.open("#{dst_name}.orig") do |io| io.write(Marshal.dump(content)) end unless @only_origin source_content = download_from_source(file) next if source_content.nil? source_content = Marshal.load(Zlib::GzipReader .new(StringIO .new(source_content)).read) new_content = source_content.concat(content).uniq Zlib::GzipWriter.open(dst_name) do |io| io.write(Marshal.dump(new_content)) end end else source_content = download_from_source(file) next if source_content.nil? MirrorFile.new(dst_name).write(source_content) end FileUtils.rm_rf(path) end end def download_from_source(file) source_host = Gemirro.configuration.source.host resp = Http.get("#{source_host}/#{File.basename(file)}") return unless resp.code == 200 resp.body end def build_indicies ::Gem::Specification.dirs = [] ::Gem::Specification.all = *map_gems_to_specs(gem_file_list) build_marshal_gemspecs build_modern_indicies if @build_modern compress_indicies end end |
#files ⇒ Array
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/gemirro/indexer.rb', line 19 class Indexer < ::Gem::Indexer attr_accessor(:files, :quick_marshal_dir, :directory, :dest_directory, :only_origin) ## # Create an indexer that will index the gems in +directory+. # # @param [String] directory Destination directory # @param [Hash] options Indexer options # @return [Array] ## def initialize(directory, = {}) require 'fileutils' require 'tmpdir' require 'zlib' unless defined?(Builder::XChar) fail 'Gem::Indexer requires that the XML Builder ' \ 'library be installed:' \ "\n\tgem install builder" end = { build_modern: true }.merge @build_modern = [:build_modern] @dest_directory = directory @directory = File.join(Dir.tmpdir, "gem_generate_index_#{rand(1_000_000_000)}") marshal_name = "Marshal.#{::Gem.marshal_version}" @master_index = File.join @directory, 'yaml' @marshal_index = File.join @directory, marshal_name @quick_dir = File.join @directory, 'quick' @quick_marshal_dir = File.join @quick_dir, marshal_name @quick_marshal_dir_base = File.join 'quick', marshal_name # FIX: UGH @quick_index = File.join @quick_dir, 'index' @latest_index = File.join @quick_dir, 'latest_index' @specs_index = File.join @directory, "specs.#{::Gem.marshal_version}" @latest_specs_index = File.join(@directory, "latest_specs.#{::Gem.marshal_version}") @prerelease_specs_index = File.join(@directory, "prerelease_specs.#{::Gem.marshal_version}") @dest_specs_index = File.join(@dest_directory, "specs.#{::Gem.marshal_version}") @dest_latest_specs_index = File.join(@dest_directory, "latest_specs.#{::Gem.marshal_version}") @dest_prerelease_specs_index = File.join(@dest_directory, "prerelease_specs.#{::Gem.marshal_version}") @files = [] end ## # Generate indicies on the destination directory # # @return [Array] # def install_indicies verbose = ::Gem.configuration.really_verbose Gemirro.configuration.logger .debug("Downloading index into production dir #{@dest_directory}") files = @files files.delete @quick_marshal_dir if files.include? @quick_dir if files.include?(@quick_marshal_dir) && !files.include?(@quick_dir) files.delete @quick_marshal_dir dst_name = File.join(@dest_directory, @quick_marshal_dir_base) FileUtils.mkdir_p(File.dirname(dst_name), verbose: verbose) FileUtils.rm_rf(dst_name, verbose: verbose) FileUtils.mv(@quick_marshal_dir, dst_name, verbose: verbose, force: true) end files.each do |path| file = path.sub(%r{^#{Regexp.escape @directory}/?}, '') dst_name = File.join @dest_directory, file if ["#{@specs_index}.gz", "#{@latest_specs_index}.gz", "#{@prerelease_specs_index}.gz"].include?(path) content = Marshal.load(Zlib::GzipReader.open(path).read) Zlib::GzipWriter.open("#{dst_name}.orig") do |io| io.write(Marshal.dump(content)) end unless @only_origin source_content = download_from_source(file) next if source_content.nil? source_content = Marshal.load(Zlib::GzipReader .new(StringIO .new(source_content)).read) new_content = source_content.concat(content).uniq Zlib::GzipWriter.open(dst_name) do |io| io.write(Marshal.dump(new_content)) end end else source_content = download_from_source(file) next if source_content.nil? MirrorFile.new(dst_name).write(source_content) end FileUtils.rm_rf(path) end end def download_from_source(file) source_host = Gemirro.configuration.source.host resp = Http.get("#{source_host}/#{File.basename(file)}") return unless resp.code == 200 resp.body end def build_indicies ::Gem::Specification.dirs = [] ::Gem::Specification.all = *map_gems_to_specs(gem_file_list) build_marshal_gemspecs build_modern_indicies if @build_modern compress_indicies end end |
#only_origin ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/gemirro/indexer.rb', line 19 class Indexer < ::Gem::Indexer attr_accessor(:files, :quick_marshal_dir, :directory, :dest_directory, :only_origin) ## # Create an indexer that will index the gems in +directory+. # # @param [String] directory Destination directory # @param [Hash] options Indexer options # @return [Array] ## def initialize(directory, = {}) require 'fileutils' require 'tmpdir' require 'zlib' unless defined?(Builder::XChar) fail 'Gem::Indexer requires that the XML Builder ' \ 'library be installed:' \ "\n\tgem install builder" end = { build_modern: true }.merge @build_modern = [:build_modern] @dest_directory = directory @directory = File.join(Dir.tmpdir, "gem_generate_index_#{rand(1_000_000_000)}") marshal_name = "Marshal.#{::Gem.marshal_version}" @master_index = File.join @directory, 'yaml' @marshal_index = File.join @directory, marshal_name @quick_dir = File.join @directory, 'quick' @quick_marshal_dir = File.join @quick_dir, marshal_name @quick_marshal_dir_base = File.join 'quick', marshal_name # FIX: UGH @quick_index = File.join @quick_dir, 'index' @latest_index = File.join @quick_dir, 'latest_index' @specs_index = File.join @directory, "specs.#{::Gem.marshal_version}" @latest_specs_index = File.join(@directory, "latest_specs.#{::Gem.marshal_version}") @prerelease_specs_index = File.join(@directory, "prerelease_specs.#{::Gem.marshal_version}") @dest_specs_index = File.join(@dest_directory, "specs.#{::Gem.marshal_version}") @dest_latest_specs_index = File.join(@dest_directory, "latest_specs.#{::Gem.marshal_version}") @dest_prerelease_specs_index = File.join(@dest_directory, "prerelease_specs.#{::Gem.marshal_version}") @files = [] end ## # Generate indicies on the destination directory # # @return [Array] # def install_indicies verbose = ::Gem.configuration.really_verbose Gemirro.configuration.logger .debug("Downloading index into production dir #{@dest_directory}") files = @files files.delete @quick_marshal_dir if files.include? @quick_dir if files.include?(@quick_marshal_dir) && !files.include?(@quick_dir) files.delete @quick_marshal_dir dst_name = File.join(@dest_directory, @quick_marshal_dir_base) FileUtils.mkdir_p(File.dirname(dst_name), verbose: verbose) FileUtils.rm_rf(dst_name, verbose: verbose) FileUtils.mv(@quick_marshal_dir, dst_name, verbose: verbose, force: true) end files.each do |path| file = path.sub(%r{^#{Regexp.escape @directory}/?}, '') dst_name = File.join @dest_directory, file if ["#{@specs_index}.gz", "#{@latest_specs_index}.gz", "#{@prerelease_specs_index}.gz"].include?(path) content = Marshal.load(Zlib::GzipReader.open(path).read) Zlib::GzipWriter.open("#{dst_name}.orig") do |io| io.write(Marshal.dump(content)) end unless @only_origin source_content = download_from_source(file) next if source_content.nil? source_content = Marshal.load(Zlib::GzipReader .new(StringIO .new(source_content)).read) new_content = source_content.concat(content).uniq Zlib::GzipWriter.open(dst_name) do |io| io.write(Marshal.dump(new_content)) end end else source_content = download_from_source(file) next if source_content.nil? MirrorFile.new(dst_name).write(source_content) end FileUtils.rm_rf(path) end end def download_from_source(file) source_host = Gemirro.configuration.source.host resp = Http.get("#{source_host}/#{File.basename(file)}") return unless resp.code == 200 resp.body end def build_indicies ::Gem::Specification.dirs = [] ::Gem::Specification.all = *map_gems_to_specs(gem_file_list) build_marshal_gemspecs build_modern_indicies if @build_modern compress_indicies end end |
#quick_marshal_dir ⇒ String
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/gemirro/indexer.rb', line 19 class Indexer < ::Gem::Indexer attr_accessor(:files, :quick_marshal_dir, :directory, :dest_directory, :only_origin) ## # Create an indexer that will index the gems in +directory+. # # @param [String] directory Destination directory # @param [Hash] options Indexer options # @return [Array] ## def initialize(directory, = {}) require 'fileutils' require 'tmpdir' require 'zlib' unless defined?(Builder::XChar) fail 'Gem::Indexer requires that the XML Builder ' \ 'library be installed:' \ "\n\tgem install builder" end = { build_modern: true }.merge @build_modern = [:build_modern] @dest_directory = directory @directory = File.join(Dir.tmpdir, "gem_generate_index_#{rand(1_000_000_000)}") marshal_name = "Marshal.#{::Gem.marshal_version}" @master_index = File.join @directory, 'yaml' @marshal_index = File.join @directory, marshal_name @quick_dir = File.join @directory, 'quick' @quick_marshal_dir = File.join @quick_dir, marshal_name @quick_marshal_dir_base = File.join 'quick', marshal_name # FIX: UGH @quick_index = File.join @quick_dir, 'index' @latest_index = File.join @quick_dir, 'latest_index' @specs_index = File.join @directory, "specs.#{::Gem.marshal_version}" @latest_specs_index = File.join(@directory, "latest_specs.#{::Gem.marshal_version}") @prerelease_specs_index = File.join(@directory, "prerelease_specs.#{::Gem.marshal_version}") @dest_specs_index = File.join(@dest_directory, "specs.#{::Gem.marshal_version}") @dest_latest_specs_index = File.join(@dest_directory, "latest_specs.#{::Gem.marshal_version}") @dest_prerelease_specs_index = File.join(@dest_directory, "prerelease_specs.#{::Gem.marshal_version}") @files = [] end ## # Generate indicies on the destination directory # # @return [Array] # def install_indicies verbose = ::Gem.configuration.really_verbose Gemirro.configuration.logger .debug("Downloading index into production dir #{@dest_directory}") files = @files files.delete @quick_marshal_dir if files.include? @quick_dir if files.include?(@quick_marshal_dir) && !files.include?(@quick_dir) files.delete @quick_marshal_dir dst_name = File.join(@dest_directory, @quick_marshal_dir_base) FileUtils.mkdir_p(File.dirname(dst_name), verbose: verbose) FileUtils.rm_rf(dst_name, verbose: verbose) FileUtils.mv(@quick_marshal_dir, dst_name, verbose: verbose, force: true) end files.each do |path| file = path.sub(%r{^#{Regexp.escape @directory}/?}, '') dst_name = File.join @dest_directory, file if ["#{@specs_index}.gz", "#{@latest_specs_index}.gz", "#{@prerelease_specs_index}.gz"].include?(path) content = Marshal.load(Zlib::GzipReader.open(path).read) Zlib::GzipWriter.open("#{dst_name}.orig") do |io| io.write(Marshal.dump(content)) end unless @only_origin source_content = download_from_source(file) next if source_content.nil? source_content = Marshal.load(Zlib::GzipReader .new(StringIO .new(source_content)).read) new_content = source_content.concat(content).uniq Zlib::GzipWriter.open(dst_name) do |io| io.write(Marshal.dump(new_content)) end end else source_content = download_from_source(file) next if source_content.nil? MirrorFile.new(dst_name).write(source_content) end FileUtils.rm_rf(path) end end def download_from_source(file) source_host = Gemirro.configuration.source.host resp = Http.get("#{source_host}/#{File.basename(file)}") return unless resp.code == 200 resp.body end def build_indicies ::Gem::Specification.dirs = [] ::Gem::Specification.all = *map_gems_to_specs(gem_file_list) build_marshal_gemspecs build_modern_indicies if @build_modern compress_indicies end end |
Instance Method Details
#build_indicies ⇒ Object
143 144 145 146 147 148 149 150 151 |
# File 'lib/gemirro/indexer.rb', line 143 def build_indicies ::Gem::Specification.dirs = [] ::Gem::Specification.all = *map_gems_to_specs(gem_file_list) build_marshal_gemspecs build_modern_indicies if @build_modern compress_indicies end |
#download_from_source(file) ⇒ Object
136 137 138 139 140 141 |
# File 'lib/gemirro/indexer.rb', line 136 def download_from_source(file) source_host = Gemirro.configuration.source.host resp = Http.get("#{source_host}/#{File.basename(file)}") return unless resp.code == 200 resp.body end |
#install_indicies ⇒ Array
Generate indicies on the destination directory
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/gemirro/indexer.rb', line 84 def install_indicies verbose = ::Gem.configuration.really_verbose Gemirro.configuration.logger .debug("Downloading index into production dir #{@dest_directory}") files = @files files.delete @quick_marshal_dir if files.include? @quick_dir if files.include?(@quick_marshal_dir) && !files.include?(@quick_dir) files.delete @quick_marshal_dir dst_name = File.join(@dest_directory, @quick_marshal_dir_base) FileUtils.mkdir_p(File.dirname(dst_name), verbose: verbose) FileUtils.rm_rf(dst_name, verbose: verbose) FileUtils.mv(@quick_marshal_dir, dst_name, verbose: verbose, force: true) end files.each do |path| file = path.sub(%r{^#{Regexp.escape @directory}/?}, '') dst_name = File.join @dest_directory, file if ["#{@specs_index}.gz", "#{@latest_specs_index}.gz", "#{@prerelease_specs_index}.gz"].include?(path) content = Marshal.load(Zlib::GzipReader.open(path).read) Zlib::GzipWriter.open("#{dst_name}.orig") do |io| io.write(Marshal.dump(content)) end unless @only_origin source_content = download_from_source(file) next if source_content.nil? source_content = Marshal.load(Zlib::GzipReader .new(StringIO .new(source_content)).read) new_content = source_content.concat(content).uniq Zlib::GzipWriter.open(dst_name) do |io| io.write(Marshal.dump(new_content)) end end else source_content = download_from_source(file) next if source_content.nil? MirrorFile.new(dst_name).write(source_content) end FileUtils.rm_rf(path) end end |