From ca755c722434c60ec172831c6959d4687c6be2ed Mon Sep 17 00:00:00 2001 From: Bundlerbot Date: Thu, 25 Oct 2018 18:39:41 +0000 Subject: [PATCH 1/2] Merge #6761 6761: fix error with path objects in array r=greysteil a=alexggordon Thanks so much for the contribution! To make reviewing this PR a bit easier, please fill out answers to the following questions. The problem was that `Pathname` instances in an array can not be sorted when there are string instances in the array also. Because of this, calling `.sort` before `.to_s` resulted in the error ``` [!] There was an error parsing `Gemfile`: comparison of Pathname with String failed. Bundler cannot continue. ``` you can easily see this issue doing ``` > require 'rails' => true > [Pathname.new("/tmp/bundle")] => [#] > [Pathname.new("/tmp/bundle"), "test"] => [#, "test"] > [Pathname.new("/tmp/bundle"), "test"].sort ArgumentError: comparison of Pathname with String failed ``` `sort` was called before `map` in the warn message. We should call `map(&:to_s)` before calling sort, and add a test case for this scenario. Because it broke our production deploys. Co-authored-by: Alex Gordon --- lib/bundler.rb | 2 +- spec/bundler/bundler_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/bundler.rb b/lib/bundler.rb index 2411ac20c2b..1cb3b4fb21e 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -371,7 +371,7 @@ def requires_sudo? unwritable_files = files.reject {|f| File.writable?(f) } sudo_needed = !unwritable_files.empty? if sudo_needed - Bundler.ui.warn "Following files may not be writable, so sudo is needed:\n #{unwritable_files.sort.map(&:to_s).join("\n ")}" + Bundler.ui.warn "Following files may not be writable, so sudo is needed:\n #{unwritable_files.map(&:to_s).sort.join("\n ")}" end end diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb index 4759005c0c9..194d6752b2c 100644 --- a/spec/bundler/bundler_spec.rb +++ b/spec/bundler/bundler_spec.rb @@ -378,9 +378,11 @@ def clear_cached_requires_sudo before do allow(Bundler).to receive(:which).with("sudo").and_return("/usr/bin/sudo") FileUtils.mkdir_p("tmp/vendor/bundle") + FileUtils.mkdir_p("tmp/vendor/bin_dir") end after do FileUtils.rm_rf("tmp/vendor/bundle") + FileUtils.rm_rf("tmp/vendor/bin_dir") if Bundler.respond_to?(:remove_instance_variable) Bundler.remove_instance_variable(:@requires_sudo_ran) Bundler.remove_instance_variable(:@requires_sudo) @@ -401,13 +403,24 @@ def clear_cached_requires_sudo before do FileUtils.touch("tmp/vendor/bundle/unwritable1.txt") FileUtils.touch("tmp/vendor/bundle/unwritable2.txt") + FileUtils.touch("tmp/vendor/bin_dir/unwritable3.txt") FileUtils.chmod(0o400, "tmp/vendor/bundle/unwritable1.txt") FileUtils.chmod(0o400, "tmp/vendor/bundle/unwritable2.txt") + FileUtils.chmod(0o400, "tmp/vendor/bin_dir/unwritable3.txt") end it "should return true and display warn message" do allow(Bundler).to receive(:bundle_path).and_return(Pathname("tmp/vendor/bundle")) + bin_dir = Pathname("tmp/vendor/bin_dir/") + + # allow File#writable? to be called with args other than the stubbed on below + allow(File).to receive(:writable?).and_call_original + + # fake make the directory unwritable + allow(File).to receive(:writable?).with(bin_dir).and_return(false) + allow(Bundler).to receive(:system_bindir).and_return(Pathname("tmp/vendor/bin_dir/")) message = <<-MESSAGE.chomp Following files may not be writable, so sudo is needed: + tmp/vendor/bin_dir/ tmp/vendor/bundle/unwritable1.txt tmp/vendor/bundle/unwritable2.txt MESSAGE From 2760d72d3b2a1070b279536c33d3a89aaad7426b Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Thu, 25 Oct 2018 12:57:38 -0700 Subject: [PATCH 2/2] Version 1.17.1 with changelog --- CHANGELOG.md | 4 ++++ lib/bundler/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 415cdd71bbc..33b9528d31f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.17.1 (2018-10-25) + + - Convert `Pathname`s to `String`s before sorting them, fixing #6760 and #6758 ([#6761](https://github.com/bundler/bundler/pull/6761), @alexggordon) + ## 1.17.0 (2018-10-25) No new changes. diff --git a/lib/bundler/version.rb b/lib/bundler/version.rb index 081b87784c0..02ec96adc96 100644 --- a/lib/bundler/version.rb +++ b/lib/bundler/version.rb @@ -7,7 +7,7 @@ module Bundler # We're doing this because we might write tests that deal # with other versions of bundler and we are unsure how to # handle this better. - VERSION = "1.17.0" unless defined?(::Bundler::VERSION) + VERSION = "1.17.1" unless defined?(::Bundler::VERSION) def self.overwrite_loaded_gem_version begin