diff --git a/CHANGELOG.md b/CHANGELOG.md index 505101214..d0ddf0765 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ BUG FIXES: a login shell (regression). [GH-2636] - core: specifying `-t` or `-T` to `vagrant ssh -c` as extra args will properly enable/disable a TTY for OpenSSH. [GH-2618] + - commands/init: Error if can't write Vagrantfile to directory. [GH-2660] - guests/debian: fix `use_dhcp_assigned_default_route` to work properly. [GH-2648] - guests/debian,ubuntu: fix change\_host\_name for FQDNs with trailing diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index ef8a43b9f..598fb9a16 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -564,6 +564,10 @@ module Vagrant error_key(:vagrantfile_syntax_error) end + class VagrantfileWriteError < VagrantError + error_key(:vagrantfile_write_error) + end + class VagrantVersionBad < VagrantError error_key(:vagrant_version_bad) end diff --git a/plugins/commands/init/command.rb b/plugins/commands/init/command.rb index c8267834f..397df2c3e 100644 --- a/plugins/commands/init/command.rb +++ b/plugins/commands/init/command.rb @@ -38,8 +38,12 @@ module VagrantPlugins if save_path # Write out the contents - save_path.open("w+") do |f| - f.write(contents) + begin + save_path.open("w+") do |f| + f.write(contents) + end + rescue Errno::EACCES + raise Vagrant::Errors::VagrantfileWriteError end @env.ui.info(I18n.t("vagrant.commands.init.success"), prefix: false) diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 80919b95d..fddfd91a4 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -676,6 +676,11 @@ en: message is reproduced below for convenience: %{file} + vagrantfile_write_error: |- + The user that is running Vagrant doesn't have the proper permissions + to write a Vagrantfile to the specified location. Please ensure that + you call `vagrant init` in a location where the proper permissions + are in place to create a Vagrantfile. vagrant_version_bad: |- This Vagrant environment has specified that it requires the Vagrant version to satisfy the following version requirements: