Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quick/Marshal.4.8 aren't download #11

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "http://rubygems.org"

gem "hoe", "~> 2.12.5"
gem "net-http-persistent", ">= 2.1"
gem "builder", ">= 2.1.2"
16 changes: 16 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
GEM
remote: http://rubygems.org/
specs:
builder (3.0.0)
hoe (2.12.5)
rake (~> 0.8)
net-http-persistent (2.3.3)
rake (0.9.2.2)

PLATFORMS
ruby

DEPENDENCIES
builder (>= 2.1.2)
hoe (~> 2.12.5)
net-http-persistent (>= 2.1)
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# rubygems-mirror

This gem can help you to full mirror of [rubygems.org](http://rubygems.org),
it is an update to the old `gem mirror` command. It uses `net/http/persistent`
and threads to grab the mirror set a little faster than the original.
Eventually it will replace `gem mirror` completely. Right now the API is not
completely stable (it will change several times before release), however, I
will maintain stability in master.

## FEATURES/PROBLEMS:

* Fast mirroring
* Limited tests - just functional

## REQUIREMENTS:

* rubygems
* net/http/persistent

## USAGE

In a file at `~/.gem/.mirrorrc` add a config that looks like the following:

---
- from: http://rubygems.org
to: /data/rubygems
parallelism: 10

Either install the gem:

$ gem install rubygems-mirror
$ gem mirror

Or clone the source code and use rake command:

$ bundle install
$ rake mirror:update


## RESOURCES

* [WebSite](http://rubygems.org/)
* [Documentation](http://rubygems.rubyforge.org/rubygems-mirror/README_rdoc.html)
* [Wiki](http://wiki.github.com/rubygems/rubygems-mirror/)
* [Source Code](http://github.com/rubygems/rubygems-mirror/)
* [Issues](http://github.com/rubygems/rubygems-mirror/issues)

## LICENSE:

(The MIT License)

Copyright (c) 2010 James Tucker, The RubyGems Team

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
71 changes: 0 additions & 71 deletions README.rdoc

This file was deleted.

2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Hoe.spec 'rubygems-mirror' do

self.extra_rdoc_files = FileList["**/*.rdoc"]
self.history_file = "CHANGELOG.rdoc"
self.readme_file = "README.rdoc"
self.readme_file = "README.md"
self.rubyforge_name = 'rubygems'
self.testlib = :minitest
end
Expand Down
69 changes: 54 additions & 15 deletions lib/rubygems/mirror.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ class Gem::Mirror
autoload :Pool, 'rubygems/mirror/pool'

VERSION = '1.0.1'

SPECS_FILE = "specs.#{Gem.marshal_version}"
SPECS_FILES = [ "specs.#{Gem.marshal_version}", "prerelease_specs.#{Gem.marshal_version}" ]
SPECS_FILE_Z = "specs.#{Gem.marshal_version}.gz"
ALL_SPECS_FILES = ["yaml","yaml.Z","latest_specs.#{Gem.marshal_version}","latest_specs.#{Gem.marshal_version}.gz",
"Marshal.#{Gem.marshal_version}", "Marshal.#{Gem.marshal_version}.Z",
"prerelease_specs.#{Gem.marshal_version}","prerelease_specs.#{Gem.marshal_version}.gz",
"specs.#{Gem.marshal_version}","specs.#{Gem.marshal_version}.gz"]

DEFAULT_URI = 'http://production.cf.rubygems.org/'
DEFAULT_TO = File.join(Gem.user_home, '.gem', 'mirror')
Expand All @@ -30,15 +34,30 @@ def to(*args)
end

def update_specs
specz = to(SPECS_FILE_Z)
@fetcher.fetch(from(SPECS_FILE_Z), specz)
open(to(SPECS_FILE), 'wb') { |f| f << Gem.gunzip(Gem.read_binary(specz)) }
SPECS_FILES.each do |sf|
sfz = "#{sf}.gz"
specz = to(sfz)
@fetcher.fetch(from(sfz), specz)
open(to(sf), 'wb') { |f| f << Gem.gunzip(Gem.read_binary(specz)) }
end
end

def fetch_all_specs
ALL_SPECS_FILES.each do |spec_file|
print "Fetching #{spec_file}..."
@fetcher.fetch(from(spec_file), to(spec_file))
puts "[Done]"
end
end

def gems
update_specs unless File.exists?(to(SPECS_FILE))
gems = []
SPECS_FILES.each do |sf|
update_specs unless File.exists?(to(sf))

gems += Marshal.load(Gem.read_binary(to(sf)))
end

gems = Marshal.load(Gem.read_binary(to(SPECS_FILE)))
gems.map! do |name, ver, plat|
# If the platform is ruby, it is not in the gem name
"#{name}-#{ver}#{"-#{plat}" unless plat == RUBY}.gem"
Expand All @@ -50,36 +69,56 @@ def existing_gems
Dir[to('gems', '*.gem')].entries.map { |f| File.basename(f) }
end

def existing_gemspecs
Dir[to("quick/Marshal.#{Gem.marshal_version}", '*.rz')].entries.map { |f| File.basename(f) }

end

def gems_to_fetch
gems - existing_gems
end

def gemspecs_to_fetch
gems.map { |g| "#{g}spec.rz" } - existing_gemspecs
end

def gems_to_delete
existing_gems - gems
end

def update_gems
fetch_all_specs
puts ""
puts "-"*100
print "#{gems_to_fetch.count} Gems need to update"
gems_to_fetch.each do |g|
@pool.job do
@fetcher.fetch(from('gems', g), to('gems', g))
print "."
yield if block_given?
end
end

@pool.run_til_done
end

def delete_gems
gems_to_delete.each do |g|
gemspecs_to_fetch.each do |g_spec|
@pool.job do
File.delete(to('gems', g))
@fetcher.fetch(from("quick/Marshal.#{Gem.marshal_version}", g_spec), to("quick/Marshal.#{Gem.marshal_version}", g_spec))
print "."
yield if block_given?
end
end

@pool.run_til_done
end

def delete_gems
# gems_to_delete.each do |g|
# @pool.job do
# File.delete(to('gems', g))
# yield if block_given?
# end
# end
#
# @pool.run_til_done
end

def update
update_specs
update_gems
Expand Down
7 changes: 5 additions & 2 deletions lib/rubygems/mirror/fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,18 @@ def handle_response(resp, path)
# Efficiently writes an http response object to a particular path. If there
# is an error, it will remove the target file.
def write_file(resp, path)
body = resp.body
return false if resp.body.length == 0
FileUtils.mkdir_p File.dirname(path)
File.open(path, 'wb') do |output|
resp.read_body { |chunk| output << chunk }
output << body
end
body = nil
true
ensure
# cleanup incomplete files, rescue perm errors etc, they're being
# raised already.
File.delete(path) rescue nil if $!
# File.delete(path) rescue nil if $!
end

end