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.
This commit is contained in:
Fernando Seror 2017-01-08 20:21:52 -05:00 committed by Brian Cain
parent 875aee3636
commit 15871a481b
2 changed files with 26 additions and 0 deletions

View File

@ -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

View File

@ -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: |-