Skip to content

Commit

Permalink
Add writable check for cache dir
Browse files Browse the repository at this point in the history
Sometimes "install_dir/cache" directory is not writable although "install_dir" is writable.
  • Loading branch information
xndcn committed Aug 4, 2020
1 parent 035984c commit 665221c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/rubygems/remote_fetcher.rb
Expand Up @@ -114,11 +114,12 @@ def download_to_cache(dependency)
# always replaced.

def download(spec, source_uri, install_dir = Gem.dir)
install_cache_dir = File.join install_dir, "cache"
cache_dir =
if Dir.pwd == install_dir # see fetch_command
install_dir
elsif File.writable? install_dir
File.join install_dir, "cache"
elsif File.writable?(install_cache_dir) || (File.writable?(install_dir) && (not File.exist?(install_cache_dir)))
install_cache_dir
else
File.join Gem.user_dir, "cache"
end
Expand Down
3 changes: 3 additions & 0 deletions test/rubygems/test_gem_remote_fetcher.rb
Expand Up @@ -321,6 +321,8 @@ def test_download_local_read_only
local_path = File.join @tempdir, @a1.file_name
inst = nil
FileUtils.chmod 0555, @a1.cache_dir
FileUtils.mkdir_p File.join(Gem.user_dir, "cache") rescue nil
FileUtils.chmod 0555, File.join(Gem.user_dir, "cache")

Dir.chdir @tempdir do
inst = Gem::RemoteFetcher.fetcher
Expand All @@ -329,6 +331,7 @@ def test_download_local_read_only
assert_equal(File.join(@tempdir, @a1.file_name),
inst.download(@a1, local_path))
ensure
FileUtils.chmod 0755, File.join(Gem.user_dir, "cache")
FileUtils.chmod 0755, @a1.cache_dir
end

Expand Down

0 comments on commit 665221c

Please sign in to comment.