On Windows, prefer USERPROFILE for home directory path
This commit is contained in:
parent
744c879998
commit
fbdd46a130
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -1,5 +1,15 @@
|
|||
## 1.2.0 (unreleased)
|
||||
|
||||
BACKWARDS INCOMPATIBILITIES:
|
||||
|
||||
- WINDOWS USERS: Vagrant now defaults to using the 'USERPROFILE' environmental
|
||||
variable for the home directory if it is set. This means that the default
|
||||
location for the Vagrant home directory is now `%USERPROFILE%/.vagrant.d`.
|
||||
On Cygwin, this will cause existing Cygwin users to "lose" their boxes.
|
||||
To work around this, either set `VAGRANT_HOME` to your Cygwin ".vagrant.d"
|
||||
folder or move your ".vagrant.d" folder to `USERPROFILE`. The latter is
|
||||
recommended for long-term support.
|
||||
|
||||
FEATURES:
|
||||
|
||||
- Providers can now parallelize! If they explicitly support it, Vagrant
|
||||
|
|
|
@ -14,7 +14,6 @@ module Vagrant
|
|||
# defined as basically a folder with a "Vagrantfile." This class allows
|
||||
# access to the VMs, CLI, etc. all in the scope of this environment.
|
||||
class Environment
|
||||
DEFAULT_HOME = "~/.vagrant.d"
|
||||
DEFAULT_LOCAL_DATA = ".vagrant"
|
||||
|
||||
# The `cwd` that this environment represents
|
||||
|
@ -554,7 +553,7 @@ module Vagrant
|
|||
def setup_home_path
|
||||
@home_path = Pathname.new(File.expand_path(@home_path ||
|
||||
ENV["VAGRANT_HOME"] ||
|
||||
DEFAULT_HOME))
|
||||
default_home_path))
|
||||
@logger.info("Home path: #{@home_path}")
|
||||
|
||||
# Setup the list of child directories that need to be created if they
|
||||
|
@ -654,6 +653,23 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
|
||||
# This returns the default home directory path for Vagrant, which
|
||||
# can differ depending on the system.
|
||||
#
|
||||
# @return [Pathname]
|
||||
def default_home_path
|
||||
path = "~/.vagrant.d"
|
||||
|
||||
# On Windows, we default ot the USERPROFILE directory if it
|
||||
# is available. This is more compatible with Cygwin and sharing
|
||||
# the home directory across shells.
|
||||
if Util::Platform.windows? && ENV["USERPROFILE"]
|
||||
path = "#{ENV["USERPROFILE"]}/.vagrant.d"
|
||||
end
|
||||
|
||||
Pathname.new(path)
|
||||
end
|
||||
|
||||
# Finds the Vagrantfile in the given directory.
|
||||
#
|
||||
# @param [Pathname] path Path to search in.
|
||||
|
|
|
@ -144,9 +144,37 @@ describe Vagrant::Environment do
|
|||
end
|
||||
end
|
||||
|
||||
it "is set to the DEFAULT_HOME by default" do
|
||||
expected = Pathname.new(File.expand_path(described_class::DEFAULT_HOME))
|
||||
described_class.new.home_path.should == expected
|
||||
context "default home path" do
|
||||
before :each do
|
||||
Vagrant::Util::Platform.stub(:windows? => false)
|
||||
end
|
||||
|
||||
it "is set to '~/.vagrant.d' by default" do
|
||||
expected = Pathname.new(File.expand_path("~/.vagrant.d"))
|
||||
described_class.new.home_path.should == expected
|
||||
end
|
||||
|
||||
it "is set to '~/.vagrant.d' if on Windows but no USERPROFILE" do
|
||||
Vagrant::Util::Platform.stub(:windows? => true)
|
||||
|
||||
expected = Pathname.new(File.expand_path("~/.vagrant.d"))
|
||||
|
||||
with_temp_env("USERPROFILE" => nil) do
|
||||
described_class.new.home_path.should == expected
|
||||
end
|
||||
end
|
||||
|
||||
it "is set to '%USERPROFILE%/.vagrant.d' if on Windows and USERPROFILE is set" do
|
||||
Vagrant::Util::Platform.stub(:windows? => true)
|
||||
|
||||
Dir.mktmpdir do |dir|
|
||||
expected = Pathname.new(File.expand_path("#{dir}/.vagrant.d"))
|
||||
|
||||
with_temp_env("USERPROFILE" => dir) do
|
||||
described_class.new.home_path.should == expected
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "throws an exception if inaccessible" do
|
||||
|
|
Loading…
Reference in New Issue