summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2017-12-01 11:38:43 -0600
committerAdam Wanninger <ajwann@ajwann.codes>2018-01-25 10:01:13 -0500
commitf0e5f9c0e85fd4d1442939bd4517814e655a0c60 (patch)
tree8e76f9e5bfc044e729b0c150e4bd7c02fac5291c /lib
parentbc072d8ffb0e9e7a56c309ef872cf71d1858ed42 (diff)
downloadbundler-f0e5f9c0e85fd4d1442939bd4517814e655a0c60.tar.gz
[CLI::Doctor] Avoid looping over all files twice
Diffstat (limited to 'lib')
-rw-r--r--lib/bundler/cli/doctor.rb50
1 files changed, 25 insertions, 25 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