Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/rubygems/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def extract_tar_gz(io, destination_dir, pattern = "*") # :nodoc:

symlinks.each do |name, target, destination, real_destination|
if File.exist?(real_destination)
File.symlink(target, destination)
create_symlink_safe(target, destination)
else
alert_warning "#{@spec.full_name} ships with a dangling symlink named #{name} pointing to missing #{target} file. Ignoring"
end
Expand Down Expand Up @@ -738,6 +738,16 @@ def limit_read(io, name, limit)
raise Gem::Package::FormatError, "#{name} is too big (over #{limit} bytes)" if bytes.size > limit
bytes
end

# Create a symlink and fallback to copy the file or directory on Windows,
# where symlink creation needs special privileges in form of the Developer Mode.
def create_symlink_safe(old_name, new_name) # :nodoc:
File.symlink(old_name, new_name)
rescue Errno::EACCES
raise unless Gem.win_platform?
from = File.expand_path(old_name, File.dirname(new_name))
FileUtils.cp_r(from, new_name)
end
end

require_relative "package/digest_io"
Expand Down