Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions lib/rubygems/doctor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def doctor_child(sub_directory, *extensions) # :nodoc:

basename = strip_extension File.basename(child), extensions
next if installed_specs.include? basename
next if sub_directory == "gems" && File.fnmatch?(".*.lock", ent) && File.file?(child)
next if /^rubygems-\d/.match?(basename)
next if sub_directory == "specifications" && basename == "default"
next if sub_directory == "plugins" && Gem.plugin_suffix_regexp =~ basename
Expand Down
42 changes: 23 additions & 19 deletions lib/rubygems/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,31 +280,35 @@ def install
# Set loaded_from to ensure extension_dir is correct
spec.loaded_from = spec_file

# Completely remove any previous gem files
FileUtils.rm_rf gem_dir
FileUtils.rm_rf spec.extension_dir
gems_dir = File.dirname(gem_dir)
ensure_writable_dir gems_dir
Gem.open_file_with_lock(File.join(gems_dir, ".#{spec.full_name}")) do
# Completely remove any previous gem files
FileUtils.rm_rf gem_dir
FileUtils.rm_rf spec.extension_dir

dir_mode = options[:dir_mode]
FileUtils.mkdir_p gem_dir, mode: dir_mode && 0o755
dir_mode = options[:dir_mode]
FileUtils.mkdir_p gem_dir, mode: dir_mode && 0o755

extract_files
extract_files

build_extensions
write_build_info_file
run_post_build_hooks
build_extensions
write_build_info_file
run_post_build_hooks

generate_bin
if options[:install_plugin] == false
remove_stale_plugins
warn_skipped_plugins
else
generate_plugins
end
generate_bin
if options[:install_plugin] == false
remove_stale_plugins
warn_skipped_plugins
else
generate_plugins
end

write_spec
write_cache_file
write_spec
write_cache_file

File.chmod(dir_mode, gem_dir) if dir_mode
File.chmod(dir_mode, gem_dir) if dir_mode
end

say clean_text(spec.post_install_message.to_s) if options[:post_install_message] && !spec.post_install_message.nil?

Expand Down
4 changes: 4 additions & 0 deletions test/rubygems/test_gem_doctor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def test_doctor

FileUtils.rm b.spec_file

lock_file = File.join(@gemhome, "gems", ".#{a.full_name}.lock")
FileUtils.touch lock_file

File.open c.spec_file, "w" do |io|
io.write "this will raise an exception when evaluated."
end
Expand All @@ -47,6 +50,7 @@ def test_doctor

assert_path_exist File.join(a.gem_dir, "Rakefile")
assert_path_exist File.join(a.gem_dir, "lib", "a.rb")
assert_path_exist lock_file

assert_path_not_exist b.gem_dir
assert_path_not_exist b.spec_file
Expand Down
24 changes: 24 additions & 0 deletions test/rubygems/test_gem_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,30 @@ def test_install
assert_same installer, @pre_install_hook_arg
end

def test_install_holds_lock_while_replacing_gem_files
installer = util_setup_installer {|s| s.executables.clear }
previous_file = File.join(installer.gem_dir, "previous")
FileUtils.touch previous_file

locked_path = nil
with_lock = lambda do |path, &install|
locked_path = path
assert_path_exist previous_file
install.call
assert_path_not_exist previous_file
assert_path_exist installer.spec.gem_build_complete_path
assert_path_exist installer.spec.cache_file
end

build_rake_in do
Gem.stub(:open_file_with_lock, with_lock) do
use_ui(@ui) { installer.install }
end
end

assert_equal File.join(@gemhome, "gems", ".#{@spec.full_name}"), locked_path
end

def test_install_creates_working_binstub
installer = util_setup_installer

Expand Down
Loading