Skip to content

Commit 9602048

Browse files
committed
Avoid failing if needs_update file is deleted by concurrent process
1 parent b1074ef commit 9602048

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

lib/ruby_lsp/setup_bundler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def update(env)
340340

341341
Bundler::CLI::Update.new({ conservative: true }, gems).run
342342
correct_relative_remote_paths if @custom_lockfile.exist?
343-
@needs_update_path.delete
343+
@needs_update_path.delete if @needs_update_path.exist?
344344
@last_updated_path.write(Time.now.iso8601)
345345
env
346346
end

test/setup_bundler_test.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,45 @@ def test_invoke_cli_calls_bundler_directly_for_update
742742
end
743743
end
744744

745+
def test_update_does_not_fail_if_needs_update_path_was_deleted_by_concurrent_process
746+
in_temp_dir do |dir|
747+
File.write(File.join(dir, "Gemfile"), <<~GEMFILE)
748+
source "https://rubygems.org"
749+
gem "rdoc"
750+
GEMFILE
751+
752+
capture_subprocess_io do
753+
Bundler.with_unbundled_env do
754+
system("bundle install")
755+
run_script(dir)
756+
end
757+
end
758+
759+
capture_subprocess_io do
760+
Bundler.with_unbundled_env do
761+
needs_update_path = File.join(dir, ".ruby-lsp", "needs_update")
762+
763+
# Simulate a concurrent process deleting the needs_update file during bundle update
764+
mock_update = mock("update")
765+
mock_update.expects(:run).with do
766+
File.delete(needs_update_path)
767+
true
768+
end
769+
require "bundler/cli/update"
770+
Bundler::CLI::Update.expects(:new).with(
771+
{ conservative: true },
772+
["ruby-lsp", "debug", "prism", "rbs"],
773+
).returns(mock_update)
774+
775+
FileUtils.touch(needs_update_path)
776+
RubyLsp::SetupBundler.new(dir, launcher: true).setup!
777+
778+
refute_path_exists(File.join(dir, ".ruby-lsp", "install_error"))
779+
end
780+
end
781+
end
782+
end
783+
745784
def test_progress_is_printed_to_stderr
746785
in_temp_dir do |dir|
747786
File.write(File.join(dir, "Gemfile"), <<~GEMFILE)

0 commit comments

Comments
 (0)