I think the problem is at https://github.com/rubygems/rubygems/blob/master/lib/rubygems/remote_fetcher.rb#L80
Basically, in RemoteFetcher#download, it's checking whether the install_dir (Gem.dir by default) is writable, and if
so, it uses that dir. However, if the user is using the --user-install option, even if the user is root, it should
not be writing outside of HOME/.gem. Basically, if the --user-install option is given, it should always download to
HOME/.gem. This may require an API change.
This affects building OpenBSD ports for some gems, since the --user-install option is used (in combination with a fake
HOME). Usually, building is done as a regular user and is fine. However, if the builder is root, rubygems adds the
.gem files to the /usr/local/lib/ruby directory when the gem is installed to HOME/.gem. Then when the package builder
goes to install the package, the cached .gem file already exists and the package install fails.
This isn't a critical bug, as it can be trivially worked around by specifying GEM_HOME=$HOME/.gem in the environment
when using gem install --user-install (which the OpenBSD ports system now does).
RubyForge issue #28726: http://rubyforge.org/tracker/?func=detail&atid=575&aid=28726&group_id=126
It now looks like we're checking writability: https://github.com/rubygems/rubygems/blob/3db265cc20b2f813dcb40758d8e1ce35ed63eaab/lib/rubygems/remote_fetcher.rb#L140