summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Nodari <andrea.nodari91@gmail.com>2017-02-09 08:54:01 +0000
committerAndrea Nodari <andrea.nodari91@gmail.com>2017-02-09 15:51:41 +0000
commit9a15da144ed6f229a1d4d8d07f5937e31248c9c8 (patch)
tree78d7cd598b5f7052b3fc372230eddfb082ac98f0
parentc0de8f625f0ae2ed5cc2b26673c875e2900a9829 (diff)
downloadbundler-9a15da144ed6f229a1d4d8d07f5937e31248c9c8.tar.gz
[Fix #5358] Handle files conflicts when using `bundle gem`
`bundle gem` command fails with an exception when creating a gem having the same name of a file in the specified path. For instance: > touch hello > bundle gem hello This bug is due to Thor gem. At the moment, Thor does not handle conflicts between files and directories. This commit mitigates the problem by rescuing the exception from Thor and gracefully exit with an error message.
-rw-r--r--lib/bundler/cli/gem.rb7
-rw-r--r--spec/commands/newgem_spec.rb22
2 files changed, 28 insertions, 1 deletions
diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb
index 955989659c..971b55b282 100644
--- a/lib/bundler/cli/gem.rb
+++ b/lib/bundler/cli/gem.rb
@@ -122,7 +122,10 @@ module Bundler
end
templates.each do |src, dst|
- thor.template("newgem/#{src}", target.join(dst), config)
+ destination = target.join(dst)
+ SharedHelpers.filesystem_access(destination) do
+ thor.template("newgem/#{src}", destination, config)
+ end
end
executables.each do |file|
@@ -139,6 +142,8 @@ module Bundler
# Open gemspec in editor
open_editor(options["edit"], target.join("#{name}.gemspec")) if options[:edit]
+ rescue Errno::EEXIST => e
+ raise GenericSystemCallError.new(e, "There was a conflict while creating the new gem.")
end
private
diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb
index 354a038cc1..7c87b9e524 100644
--- a/spec/commands/newgem_spec.rb
+++ b/spec/commands/newgem_spec.rb
@@ -835,4 +835,26 @@ Usage: "bundle gem GEM [OPTIONS]"
expect(bundled_app("foobar/CODE_OF_CONDUCT.md")).to exist
end
end
+
+ context "on conflicts with a previously created file" do
+ it "should fail gracefully" do
+ in_app_root do
+ FileUtils.touch("conflict-foobar")
+ end
+ output = bundle "gem conflict-foobar"
+ expect(output).to include("Errno::EEXIST")
+ expect(exitstatus).to eql(32) if exitstatus
+ end
+ end
+
+ context "on conflicts with a previously created directory" do
+ it "should fail gracefully" do
+ in_app_root do
+ FileUtils.mkdir_p("conflict-foobar/Gemfile")
+ end
+ output = bundle "gem conflict-foobar"
+ expect(output).to include("Errno::EISDIR")
+ expect(exitstatus).to eql(32) if exitstatus
+ end
+ end
end