Permalink
Browse files

Remote Fetcher should fall back to cache in ~ if regular cache isn't …

…writable.

git-svn-id: http://rubygems.rubyforge.org/svn/trunk@1816 3d4018f9-ac1a-0410-99e9-8a154d859a19
  • Loading branch information...
technomancy
technomancy committed Jun 24, 2008
1 parent c09b955 commit e6981fd10d7825e3dd157832f33a4147daf8b139
Showing with 14 additions and 11 deletions.
  1. +6 −1 lib/rubygems/remote_fetcher.rb
  2. +8 −10 test/test_gem_remote_fetcher.rb
@@ -75,7 +75,12 @@ def initialize(proxy)
# always replaced.
def download(spec, source_uri, install_dir = Gem.dir)
- cache_dir = File.join install_dir, 'cache'
+ if File.writable?(install_dir)
+ cache_dir = File.join install_dir, 'cache'
+ else
+ cache_dir = File.join(ENV['HOME'], '.gem', 'cache')
+ end
+
gem_file_name = "#{spec.full_name}.gem"
local_gem_path = File.join cache_dir, gem_file_name
@@ -248,6 +248,7 @@ def test_download_install_dir
install_dir = File.join @tempdir, 'more_gems'
a1_cache_gem = File.join install_dir, 'cache', "#{@a1.full_name}.gem"
+ FileUtils.mkdir_p(File.dirname(a1_cache_gem))
actual = fetcher.download(@a1, 'http://gems.example.com', install_dir)
assert_equal a1_cache_gem, actual
@@ -257,7 +258,7 @@ def test_download_install_dir
assert File.exist?(a1_cache_gem)
end
- unless win_platform? then # File.chmod doesn't work
+ unless win_platform? # File.chmod doesn't work
def test_download_local_read_only
FileUtils.mv @a1_gem, @tempdir
local_path = File.join @tempdir, "#{@a1.full_name}.gem"
@@ -275,19 +276,16 @@ def test_download_local_read_only
end
def test_download_read_only
- fetch_dir = File.join(@tempdir, 'more_gems')
- FileUtils.mkdir(fetch_dir)
File.chmod 0555, File.join(@gemhome, 'cache')
- File.chmod 0555, @tempdir
+ File.chmod 0555, File.join(@gemhome)
- Dir.chdir fetch_dir do
- fetcher = util_fuck_with_fetcher File.read(@a1_gem)
- fetcher.download(@a1, 'http://gems.example.com')
- assert File.exist?(File.join(fetch_dir, "#{@a1.full_name}.gem"))
- end
+ fetcher = util_fuck_with_fetcher File.read(@a1_gem)
+ fetcher.download(@a1, 'http://gems.example.com')
+ assert File.exist?(File.join(@userhome, '.gem',
+ 'cache', "#{@a1.full_name}.gem"))
ensure
+ File.chmod 0755, File.join(@gemhome)
File.chmod 0755, File.join(@gemhome, 'cache')
- File.chmod 0755, @tempdir
end
end

0 comments on commit e6981fd

Please sign in to comment.