summaryrefslogtreecommitdiff
path: root/lib/bundler.rb
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2022-09-05 09:15:30 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2022-09-05 14:37:12 +0900
commit3eca1e438db6fabaa7cd5e5a7120da147ac0ec26 (patch)
tree597be042af7d0052616ba41bb9d0b8d8ceedd094 /lib/bundler.rb
parent3767c6a90d8970f9b39e9ed116a7b9bbac3f9f26 (diff)
Merge https://github.com/rubygems/rubygems/commit/16c3535413afebcdbab7582c6017c27b5da8a8dc
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6326
Diffstat (limited to 'lib/bundler.rb')
-rw-r--r--lib/bundler.rb61
1 files changed, 2 insertions, 59 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 24785ef5eb..dc88bbdcb9 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -488,41 +488,9 @@ EOF
configured_bundle_path.use_system_gems?
end
- def requires_sudo?
- return @requires_sudo if defined?(@requires_sudo_ran)
-
- sudo_present = which "sudo" if settings.allow_sudo?
-
- if sudo_present
- # the bundle path and subdirectories need to be writable for RubyGems
- # to be able to unpack and install gems without exploding
- path = bundle_path
- path = path.parent until path.exist?
-
- # bins are written to a different location on OS X
- bin_dir = Pathname.new(Bundler.system_bindir)
- bin_dir = bin_dir.parent until bin_dir.exist?
-
- # if any directory is not writable, we need sudo
- files = [path, bin_dir] | Dir[bundle_path.join("build_info/*").to_s] | Dir[bundle_path.join("*").to_s]
- 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.map(&:to_s).sort.join("\n ")}"
- end
- end
-
- @requires_sudo_ran = true
- @requires_sudo = settings.allow_sudo? && sudo_present && sudo_needed
- end
-
def mkdir_p(path, options = {})
- if requires_sudo? && !options[:no_sudo]
- sudo "mkdir -p '#{path}'" unless File.exist?(path)
- else
- SharedHelpers.filesystem_access(path, :write) do |p|
- FileUtils.mkdir_p(p)
- end
+ SharedHelpers.filesystem_access(path, :write) do |p|
+ FileUtils.mkdir_p(p)
end
end
@@ -539,31 +507,6 @@ EOF
end
end
- def sudo(str)
- SUDO_MUTEX.synchronize do
- prompt = "\n\n" + <<-PROMPT.gsub(/^ {6}/, "").strip + " "
- Your user account isn't allowed to install to the system RubyGems.
- You can cancel this installation and run:
-
- bundle config set --local path 'vendor/bundle'
- bundle install
-
- to install the gems into ./vendor/bundle/, or you can enter your password
- and install the bundled gems to RubyGems using sudo.
-
- Password:
- PROMPT
-
- unless @prompted_for_sudo ||= system(%(sudo -k -p "#{prompt}" true))
- raise SudoNotPermittedError,
- "Bundler requires sudo access to install at the moment. " \
- "Try installing again, granting Bundler sudo access when prompted, or installing into a different path."
- end
-
- `sudo -p "#{prompt}" #{str}`
- end
- end
-
def read_file(file)
SharedHelpers.filesystem_access(file, :read) do
File.open(file, "r:UTF-8", &:read)