summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rodríguez <[email protected]>2024-10-21 19:20:09 +0200
committergit <[email protected]>2024-10-23 08:53:18 +0000
commitcc29d737ef1cee9e1b18c54112afdbd3311f3e37 (patch)
treee0b07d80e46ec259af7733f0dca0b67ad6dca578
parent88b969cd19d48d3d20f2a3cd0cbf6d97e46636fc (diff)
[rubygems/rubygems] Consistently use `:create` action when creating directories
It gives better errors. https://github.com/rubygems/rubygems/commit/bedae080ef
-rw-r--r--lib/bundler.rb2
-rw-r--r--lib/bundler/settings.rb6
-rw-r--r--lib/bundler/shared_helpers.rb2
-rw-r--r--spec/bundler/bundler/settings_spec.rb18
-rw-r--r--spec/bundler/commands/install_spec.rb2
5 files changed, 18 insertions, 12 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index a195405fd9..3cb1f076a0 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -493,7 +493,7 @@ module Bundler
end
def mkdir_p(path)
- SharedHelpers.filesystem_access(path, :write) do |p|
+ SharedHelpers.filesystem_access(path, :create) do |p|
FileUtils.mkdir_p(p)
end
end
diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb
index 878747a53b..4dda36242d 100644
--- a/lib/bundler/settings.rb
+++ b/lib/bundler/settings.rb
@@ -425,8 +425,12 @@ module Bundler
Validator.validate!(raw_key, converted_value(value, raw_key), hash)
return unless file
+
+ SharedHelpers.filesystem_access(file.dirname, :create) do |p|
+ FileUtils.mkdir_p(p)
+ end
+
SharedHelpers.filesystem_access(file) do |p|
- FileUtils.mkdir_p(p.dirname)
p.open("w") {|f| f.write(serializer_class.dump(hash)) }
end
end
diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb
index efdc0fe8f5..37fe319f49 100644
--- a/lib/bundler/shared_helpers.rb
+++ b/lib/bundler/shared_helpers.rb
@@ -96,7 +96,7 @@ module Bundler
# given block
#
# @example
- # filesystem_access("vendor/cache", :write) do
+ # filesystem_access("vendor/cache", :create) do
# FileUtils.mkdir_p("vendor/cache")
# end
#
diff --git a/spec/bundler/bundler/settings_spec.rb b/spec/bundler/bundler/settings_spec.rb
index b7db548cf9..7c64c1c907 100644
--- a/spec/bundler/bundler/settings_spec.rb
+++ b/spec/bundler/bundler/settings_spec.rb
@@ -121,12 +121,13 @@ that would suck --ehhh=oh geez it looks like i might have broken bundler somehow
end
end
- context "when it's not possible to write to the file" do
+ context "when it's not possible to create the settings directory" do
it "raises an PermissionError with explanation" do
- expect(::Bundler::FileUtils).to receive(:mkdir_p).with(settings.send(:local_config_file).dirname).
- and_raise(Errno::EACCES)
+ settings_dir = settings.send(:local_config_file).dirname
+ expect(::Bundler::FileUtils).to receive(:mkdir_p).with(settings_dir).
+ and_raise(Errno::EACCES.new(settings_dir.to_s))
expect { settings.set_local :frozen, "1" }.
- to raise_error(Bundler::PermissionError, /config/)
+ to raise_error(Bundler::PermissionError, /#{settings_dir}/)
end
end
end
@@ -164,12 +165,13 @@ that would suck --ehhh=oh geez it looks like i might have broken bundler somehow
end
describe "#set_global" do
- context "when it's not possible to write to the file" do
+ context "when it's not possible to write to create the settings directory" do
it "raises an PermissionError with explanation" do
- expect(::Bundler::FileUtils).to receive(:mkdir_p).with(settings.send(:global_config_file).dirname).
- and_raise(Errno::EACCES)
+ settings_dir = settings.send(:global_config_file).dirname
+ expect(::Bundler::FileUtils).to receive(:mkdir_p).with(settings_dir).
+ and_raise(Errno::EACCES.new(settings_dir.to_s))
expect { settings.set_global(:frozen, "1") }.
- to raise_error(Bundler::PermissionError, %r{\.bundle/config})
+ to raise_error(Bundler::PermissionError, /#{settings_dir}/)
end
end
end
diff --git a/spec/bundler/commands/install_spec.rb b/spec/bundler/commands/install_spec.rb
index 1dcac7ce8a..a47f62464f 100644
--- a/spec/bundler/commands/install_spec.rb
+++ b/spec/bundler/commands/install_spec.rb
@@ -890,7 +890,7 @@ RSpec.describe "bundle install with gem sources" do
bundle "config set --local path vendor"
bundle :install, raise_on_error: false
expect(err).to include(bundle_path.to_s)
- expect(err).to include("grant write permissions")
+ expect(err).to include("grant executable permissions")
end
end