From 15871a481bdca3008471deca582f79c5a5fe7578 Mon Sep 17 00:00:00 2001 From: Fernando Seror Date: Sun, 8 Jan 2017 20:21:52 -0500 Subject: [PATCH] Warn about changes to CWD on every machine action Whenever the path where the machine was first created changes, Vagrant will now show just one warning when an action is run on the machine. The idea is that if a user copies the machine over to a different directory with the idea of running two different machines, this warning will now help the user determine how to make that work. --- lib/vagrant/machine.rb | 22 ++++++++++++++++++++++ templates/locales/en.yml | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index e7107fb62..a3b13373e 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -170,6 +170,8 @@ module Vagrant # Extra env keys are the remaining opts extra_env = opts.dup + check_cwd + # Create a deterministic ID for this machine vf = nil vf = @env.vagrantfile_name[0] if @env.vagrantfile_name @@ -559,5 +561,25 @@ module Vagrant return nil if !@data_dir @data_dir.join("creator_uid") end + + def check_cwd + vagrant_cwd_filepath = @data_dir.join('vagrant_cwd') + vagrant_cwd = if File.exist?(vagrant_cwd_filepath) + File.read(vagrant_cwd_filepath).chomp + end + + if vagrant_cwd + if vagrant_cwd != @env.cwd.to_s + ui.warn(I18n.t( + 'vagrant.moved_cwd', + old_wd: vagrant_cwd, + current_wd: @env.cwd.to_s)) + + File.write(vagrant_cwd_filepath, @env.cwd) + end + else + File.write(vagrant_cwd_filepath, @env.cwd) + end + end end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 5e36d67a4..2e6a6f5e9 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -165,6 +165,10 @@ en: description of what they do. %{list} + moved_cwd: |- + This machine used to live in %{old_wd} but it's now at %{current_wd}. + Please change the name of the machine if you want to run it as a different + machine. guest_deb_installing_smb: |- Installing SMB "mount.cifs"... global_status_footer: |-