From c6a9c81021092c9157f5616a2bbe1323411a5bf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 9 Dec 2021 12:46:23 +0100 Subject: [PATCH] Resolve symlinks in LOAD_PATH when activating pre-required default gems 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. --- lib/rubygems.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 11474b6554c4..b7dda38d5225 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -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