Skip to content

Commit

Permalink
Resolve symlinks in LOAD_PATH when activating pre-required default gems
Browse files Browse the repository at this point in the history
Some double load issues were reported a while ago by OS packagers where
if a gem has been required before rubygems, and then after, rubygems
require would cause a double load.

We avoid this issue by activating the corresponding gem if we detect
that a file in the default LOAD_PATH that belongs to a default gem has
already been required when rubygems registers default gems.

However, the fix does not take into account that the default LOAD_PATH
could potentially include symlinks. This change fixes the same double
load issue described above but for situations where the default
LOAD_PATH includes symlinks.
  • Loading branch information
deivid-rodriguez committed Dec 10, 2021
1 parent 52cfdd1 commit c6a9c81
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rubygems.rb
Expand Up @@ -1293,7 +1293,12 @@ def already_loaded?(file)
end

def default_gem_load_paths
@default_gem_load_paths ||= $LOAD_PATH[load_path_insert_index..-1]
@default_gem_load_paths ||= $LOAD_PATH[load_path_insert_index..-1].map do |lp|
expanded = File.expand_path(lp)
next expanded unless File.exist?(expanded)

File.realpath(expanded)
end
end
end

Expand Down

0 comments on commit c6a9c81

Please sign in to comment.