summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/bundler/cli/doctor.rb50
-rw-r--r--spec/commands/doctor_spec.rb7
2 files changed, 30 insertions, 27 deletions
diff --git a/lib/bundler/cli/doctor.rb b/lib/bundler/cli/doctor.rb
index e4e15fe1a2..e7294eb285 100644
--- a/lib/bundler/cli/doctor.rb
+++ b/lib/bundler/cli/doctor.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require "rbconfig"
-require "find"
module Bundler
class CLI::Doctor
@@ -62,7 +61,6 @@ module Bundler
end
def run
- check_home_permissions
Bundler.ui.level = "error" if options[:quiet]
Bundler.settings.validate!
check!
@@ -80,6 +78,8 @@ module Bundler
end
end
+ permissions_valid = check_home_permissions
+
if broken_links.any?
message = "The following gems are missing OS dependencies:"
broken_links.map do |spec, paths|
@@ -88,7 +88,7 @@ module Bundler
end
end.flatten.sort.each {|m| message += m }
raise ProductionError, message
- else
+ elsif !permissions_valid
Bundler.ui.info "No issues found with the installed bundle"
end
end
@@ -96,33 +96,33 @@ module Bundler
private
def check_home_permissions
- check_for_files_not_owned_by_current_user_but_still_rw
- check_for_files_not_readable_or_writable
- end
-
- def check_for_files_not_owned_by_current_user_but_still_rw
- return unless files_not_owned_by_current_user_but_still_rw.any?
- Bundler.ui.warn "Files exist in Bundler home that are owned by another " \
- "user, but are stil readable/writable. These files are:\n - #{files_not_owned_by_current_user_but_still_rw.join("\n - ")}"
- end
+ require "find"
+ files_not_readable_or_writable = []
+ files_not_owned_by_current_user_but_still_rw = []
+ Find.find(Bundler.home.to_s).each do |f|
+ if !File.writable?(f) || !File.readable?(f)
+ files_not_readable_or_writable << f
+ elsif File.stat(f).uid != Process.uid
+ files_not_owned_by_current_user_but_still_rw << f
+ end
+ end
- def check_for_files_not_readable_or_writable
- return unless files_not_readable_or_writable.any?
- Bundler.ui.warn "Files exist in Bundler home that are not " \
- "readable/writable to the current user. These files are:\n - #{files_not_readable_or_writable.join("\n - ")}"
- end
+ ok = true
+ if files_not_owned_by_current_user_but_still_rw.any?
+ Bundler.ui.warn "Files exist in the Bundler home that are owned by another " \
+ "user, but are stil readable/writable. These files are:\n - #{files_not_owned_by_current_user_but_still_rw.join("\n - ")}"
- def files_not_readable_or_writable
- Find.find(Bundler.home.to_s).select do |f|
- !(File.writable?(f) && File.readable?(f))
+ ok = false
end
- end
- def files_not_owned_by_current_user_but_still_rw
- Find.find(Bundler.home.to_s).select do |f|
- (File.stat(f).uid != Process.uid) &&
- (File.writable?(f) && File.readable?(f))
+ if files_not_readable_or_writable.any?
+ Bundler.ui.warn "Files exist in the Bundler home that are not " \
+ "readable/writable to the current user. These files are:\n - #{files_not_readable_or_writable.join("\n - ")}"
+
+ ok = false
end
+
+ ok
end
end
end
diff --git a/spec/commands/doctor_spec.rb b/spec/commands/doctor_spec.rb
index 6d2c5ef6a3..ef33bedb57 100644
--- a/spec/commands/doctor_spec.rb
+++ b/spec/commands/doctor_spec.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
+require "find"
require "stringio"
require "bundler/cli"
require "bundler/cli/doctor"
@@ -68,8 +69,9 @@ RSpec.describe "bundle doctor" do
allow(File).to receive(:readable?).with(unwritable_file) { false }
expect { doctor.run }.not_to raise_error
expect(@stdout.string).to include(
- "Files exist in Bundler home that are not readable/writable to the current user. These files are:\n - #{unwritable_file}"
+ "Files exist in the Bundler home that are not readable/writable to the current user. These files are:\n - #{unwritable_file}"
)
+ expect(@stdout.string).not_to include("No issues")
end
it "exits with a warning if home contains files that are read/write but not owned by current user" do
@@ -82,7 +84,8 @@ RSpec.describe "bundle doctor" do
allow(File).to receive(:readable?).with(unwritable_file) { true }
expect { Bundler::CLI::Doctor.new({}).run }.not_to raise_error
expect(@stdout.string).to include(
- "Files exist in Bundler home that are owned by another user, but are stil readable/writable. These files are:\n - #{unwritable_file}"
+ "Files exist in the Bundler home that are owned by another user, but are stil readable/writable. These files are:\n - #{unwritable_file}"
)
+ expect(@stdout.string).not_to include("No issues")
end
end