Skip to content

Commit 5911a52

Browse files
hsbtmatzbot
authored andcommitted
[ruby/rubygems] Handle symlink TMPDIR with macOS
ruby/rubygems@cf08f1ec4c
1 parent 9bf8aaa commit 5911a52

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

spec/bundler/bundler/gem_helper_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ def sha512_hexdigest(path)
386386
credentials = double("credentials", "file?" => true)
387387
allow(Bundler.user_home).to receive(:join).
388388
with(".gem/credentials").and_return(credentials)
389+
allow(Bundler.user_home).to receive(:join).and_call_original
389390
end
390391

391392
describe "success messaging" do

spec/bundler/support/path.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,17 @@ def tmp(*path)
114114
end
115115

116116
def tmp_root
117-
ruby_core? && (tmpdir = ENV["TMPDIR"]) ? Pathname(tmpdir) : source_root.join("tmp")
117+
if ruby_core? && (tmpdir = ENV["TMPDIR"])
118+
# Use realpath to resolve any symlinks in TMPDIR (e.g., on macOS /var -> /private/var)
119+
real = begin
120+
File.realpath(tmpdir)
121+
rescue Errno::ENOENT, Errno::EACCES
122+
tmpdir
123+
end
124+
Pathname(real)
125+
else
126+
source_root.join("tmp")
127+
end
118128
end
119129

120130
# Bump this version whenever you make a breaking change to the spec setup

spec/bundler/support/rubygems_ext.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,18 @@ def test_setup
4343
# sign extension bundles on macOS, to avoid trying to find the specified key
4444
# from the fake $HOME/Library/Keychains directory.
4545
ENV.delete "RUBY_CODESIGN"
46-
ENV["TMPDIR"] = Path.tmpdir.to_s unless Path.ruby_core?
46+
if Path.ruby_core?
47+
if (tmpdir = ENV["TMPDIR"])
48+
tmpdir_real = begin
49+
File.realpath(tmpdir)
50+
rescue Errno::ENOENT, Errno::EACCES
51+
tmpdir
52+
end
53+
ENV["TMPDIR"] = tmpdir_real if tmpdir_real != tmpdir
54+
end
55+
else
56+
ENV["TMPDIR"] = Path.tmpdir.to_s
57+
end
4758

4859
require "rubygems/user_interaction"
4960
Gem::DefaultUserInteraction.ui = Gem::SilentUI.new

0 commit comments

Comments
 (0)