mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
[rubygems/rubygems] Handle RubyGems installing to custom dir with non-existent parent dirs
4701123601
This commit is contained in:
parent
8f009601f9
commit
a1d62a3b1c
3 changed files with 45 additions and 5 deletions
|
@ -953,11 +953,7 @@ TEXT
|
|||
end
|
||||
|
||||
def ensure_writable_dir(dir) # :nodoc:
|
||||
begin
|
||||
Dir.mkdir dir, *[options[:dir_mode] && 0o755].compact
|
||||
rescue SystemCallError
|
||||
raise unless File.directory? dir
|
||||
end
|
||||
FileUtils.mkdir_p dir, mode: options[:dir_mode] && 0o755
|
||||
|
||||
raise Gem::FilePermissionError.new(dir) unless File.writable? dir
|
||||
end
|
||||
|
|
|
@ -221,6 +221,23 @@ class Gem::InstallerTestCase < Gem::TestCase
|
|||
force: force)
|
||||
end
|
||||
|
||||
def test_ensure_writable_dir_creates_missing_parent_directories
|
||||
installer = setup_base_installer(false)
|
||||
|
||||
non_existent_parent = File.join(@tempdir, "non_existent_parent")
|
||||
target_dir = File.join(non_existent_parent, "target_dir")
|
||||
|
||||
refute_directory_exists non_existent_parent, "Parent directory should not exist yet"
|
||||
refute_directory_exists target_dir, "Target directory should not exist yet"
|
||||
|
||||
assert_nothing_raised do
|
||||
installer.send(:ensure_writable_dir, target_dir)
|
||||
end
|
||||
|
||||
assert_directory_exists non_existent_parent, "Parent directory should exist now"
|
||||
assert_directory_exists target_dir, "Target directory should exist now"
|
||||
end
|
||||
|
||||
@@symlink_supported = nil
|
||||
|
||||
# This is needed for Windows environment without symlink support enabled (the default
|
||||
|
|
|
@ -1583,4 +1583,31 @@ ERROR: Possible alternatives: non_existent_with_hint
|
|||
assert_includes @ui.output, "A new release of RubyGems is available: 1.2.3 → 2.0.0!"
|
||||
end
|
||||
end
|
||||
|
||||
def test_execute_bindir_with_nonexistent_parent_dirs
|
||||
spec_fetcher do |fetcher|
|
||||
fetcher.gem "a", 2 do |s|
|
||||
s.executables = %w[a_bin]
|
||||
s.files = %w[bin/a_bin]
|
||||
end
|
||||
end
|
||||
|
||||
@cmd.options[:args] = %w[a]
|
||||
|
||||
nested_bin_dir = File.join(@tempdir, "not", "exists")
|
||||
refute_directory_exists nested_bin_dir, "Nested bin directory should not exist yet"
|
||||
|
||||
@cmd.options[:bin_dir] = nested_bin_dir
|
||||
|
||||
use_ui @ui do
|
||||
assert_raise Gem::MockGemUi::SystemExitException, @ui.error do
|
||||
@cmd.execute
|
||||
end
|
||||
end
|
||||
|
||||
assert_directory_exists nested_bin_dir, "Nested bin directory should exist now"
|
||||
assert_path_exist File.join(nested_bin_dir, "a_bin")
|
||||
|
||||
assert_equal %w[a-2], @cmd.installed_specs.map(&:full_name)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue