[rubygems/rubygems] Don't write outside of destdir when regenerating plugins

https://github.com/rubygems/rubygems/commit/141ef4cb9a
This commit is contained in:
David Rodríguez 2021-11-05 20:57:41 +01:00 коммит произвёл git
Родитель 9dc76e102e
Коммит a72aecac3a
3 изменённых файлов: 24 добавлений и 2 удалений

Просмотреть файл

@ -50,6 +50,11 @@ class Gem::Commands::PristineCommand < Gem::Command
options[:env_shebang] = value
end
add_option('-i', '--install-dir DIR',
'Gem repository to get binstubs and plugins installed') do |value, options|
options[:install_dir] = File.expand_path(value)
end
add_option('-n', '--bindir DIR',
'Directory where executables are',
'located') do |value, options|
@ -163,11 +168,12 @@ extensions will be restored.
end
bin_dir = options[:bin_dir] if options[:bin_dir]
install_dir = options[:install_dir] if options[:install_dir]
installer_options = {
:wrappers => true,
:force => true,
:install_dir => spec.base_dir,
:install_dir => install_dir || spec.base_dir,
:env_shebang => env_shebang,
:build_args => spec.build_args,
:bin_dir => bin_dir,
@ -177,7 +183,7 @@ extensions will be restored.
installer = Gem::Installer.for_spec(spec, installer_options)
installer.generate_bin
elsif options[:only_plugins]
installer = Gem::Installer.for_spec(spec)
installer = Gem::Installer.for_spec(spec, installer_options)
installer.generate_plugins
else
installer = Gem::Installer.at(gem, installer_options)

Просмотреть файл

@ -610,6 +610,7 @@ abort "#{deprecation_message}"
args = %w[--all --only-plugins --silent]
args << "--bindir=#{bindir}"
args << "--install-dir=#{default_dir}"
command = Gem::Commands::PristineCommand.new
command.invoke(*args)

Просмотреть файл

@ -156,6 +156,21 @@ class TestGemCommandsSetupCommand < Gem::TestCase
assert_match %r{\A#!\s*#{bin_env}#{ruby_exec}}, File.read(gem_bin_path)
end
def test_destdir_flag_does_not_try_to_write_to_the_default_gem_home
FileUtils.chmod "-w", File.join(@gemhome, "plugins")
destdir = File.join(@tempdir, 'foo')
@cmd.options[:destdir] = destdir
@cmd.execute
spec = Gem::Specification.load("bundler/bundler.gemspec")
spec.executables.each do |e|
assert_path_exist File.join destdir, @gemhome.gsub(/^[a-zA-Z]:/, ''), 'gems', spec.full_name, spec.bindir, e
end
end
def test_files_in
assert_equal %w[rubygems.rb rubygems/requirement.rb rubygems/ssl_certs/rubygems.org/foo.pem],
@cmd.files_in('lib').sort