summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/bundler.rb4
-rw-r--r--lib/bundler/source/rubygems.rb2
-rw-r--r--spec/bundler/bundler_spec.rb28
3 files changed, 31 insertions, 3 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 8e30bc4f57..7904496e96 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -373,8 +373,8 @@ EOF
@requires_sudo = settings.allow_sudo? && sudo_present && sudo_needed
end
- def mkdir_p(path)
- if requires_sudo?
+ 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|
diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb
index 1759838b57..2f4a2fdac8 100644
--- a/lib/bundler/source/rubygems.rb
+++ b/lib/bundler/source/rubygems.rb
@@ -144,7 +144,7 @@ module Bundler
bin_path = Bundler.system_bindir
end
- Bundler.mkdir_p bin_path unless spec.executables.empty? || Bundler.rubygems.provides?(">= 2.7.5")
+ Bundler.mkdir_p bin_path, :no_sudo => true unless spec.executables.empty? || Bundler.rubygems.provides?(">= 2.7.5")
installed_spec = nil
Bundler.rubygems.preserve_paths do
diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb
index 131146119e..ecff1b0d28 100644
--- a/spec/bundler/bundler_spec.rb
+++ b/spec/bundler/bundler_spec.rb
@@ -190,6 +190,34 @@ EOF
end
end
+ describe "#mkdir_p" do
+ it "creates a folder at the given path" do
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rack"
+ G
+
+ Bundler.mkdir_p(bundled_app.join("foo", "bar"))
+ expect(bundled_app.join("foo", "bar")).to exist
+ end
+
+ context "when mkdir_p requires sudo" do
+ it "creates a new folder using sudo" do
+ expect(Bundler).to receive(:requires_sudo?).and_return(true)
+ expect(Bundler).to receive(:sudo).and_return true
+ Bundler.mkdir_p(bundled_app.join("foo"))
+ end
+ end
+
+ context "with :no_sudo option" do
+ it "forces mkdir_p to not use sudo" do
+ expect(Bundler).to receive(:requires_sudo?).and_return(true)
+ expect(Bundler).to_not receive(:sudo)
+ Bundler.mkdir_p(bundled_app.join("foo"), :no_sudo => true)
+ end
+ end
+ end
+
describe "#user_home" do
context "home directory is set" do
it "should return the user home" do