# File lib/bundler.rb, line 354defrequires_sudo?return@requires_sudoifdefined?(@requires_sudo_ran)
sudo_present = which"sudo"ifsettings.allow_sudo?ifsudo_present# the bundle path and subdirectories need to be writable for RubyGems# to be able to unpack and install gems without explodingpath = bundle_pathpath = path.parentuntilpath.exist?# bins are written to a different location on OS Xbin_dir = Pathname.new(Bundler.system_bindir)
bin_dir = bin_dir.parentuntilbin_dir.exist?# if any directory is not writable, we need sudofiles = [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?ifsudo_neededBundler.ui.warn"Following files may not be writable, so sudo is needed:\n #{unwritable_files.map(&:to_s).sort.join("\n ")}"endend@requires_sudo_ran = true@requires_sudo = settings.allow_sudo?&&sudo_present&&sudo_neededend

# File lib/bundler.rb, line 260defrm_rf(path)
FileUtils.remove_entry_secure(path) ifpath&&File.exist?(path)
rescueArgumentErrormessage = <<EOFIt is a security vulnerability to allow your home directory to be world-writable, and bundler can not continue.
You should probably consider fixing this issue by running `chmod o-w ~` on *nix.
Please refer to http://ruby-doc.org/stdlib-2.1.2/libdoc/fileutils/rdoc/FileUtils.html#method-c-remove_entry_secure for details.
EOFFile.world_writable?(path) ?Bundler.ui.warn(message) :raiseraisePathError, "Please fix the world-writable issue with your #{path} directory"end

# File lib/bundler.rb, line 97defsetup(*groups)
# Return if all groups are already loadedreturn@setupifdefined?(@setup) &&@setupdefinition.validate_runtime!SharedHelpers.print_major_deprecations!ifgroups.empty?# Load all groups, but only once@setup = load.setupelseload.setup(*groups)
endend

specs_path()click to toggle source

# File lib/bundler.rb, line 228defspecs_pathbundle_path.join("specifications")
end

sudo(str)click to toggle source

# File lib/bundler.rb, line 405defsudo(str)
SUDO_MUTEX.synchronizedoprompt = "\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 install --path vendor/bundle
to install the gems into ./vendor/bundle/, or you can enter your password
and install the bundled gems to RubyGems using sudo.
Password:
PROMPTunless@prompted_for_sudo||=system(%(sudo -k -p "#{prompt}" true))
raiseSudoNotPermittedError,
"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}`endend

system_bindir()click to toggle source

# File lib/bundler.rb, line 341defsystem_bindir# Gem.bindir doesn't always return the location that RubyGems will install# system binaries. If you put '-n foo' in your .gemrc, RubyGems will# install binstubs there instead. Unfortunately, RubyGems doesn't expose# that directory at all, so rather than parse .gemrc ourselves, we allow# the directory to be set as well, via `bundle config bindir foo`.Bundler.settings[:system_bindir] ||Bundler.rubygems.gem_bindirend

# File lib/bundler.rb, line 511defeval_yaml_gemspec(path, contents)
Kernel.send(:require, "bundler/psyched_yaml")
# If the YAML is invalid, Syck raises an ArgumentError, and Psych# raises a Psych::SyntaxError. See psyched_yaml.rb for more info.Gem::Specification.from_yaml(contents)
rescueYamlLibrarySyntaxError, ArgumentError, Gem::EndOfYAMLException, Gem::Exceptioneval_gemspec(path, contents)
end