Vagrant::Env sets up the home directory (specified in config) with proper subfolders if they don't exist.
This commit is contained in:
parent
f1fda1f0fa
commit
2b1afa6f6f
|
@ -1,6 +1,7 @@
|
|||
module Vagrant
|
||||
class Env
|
||||
ROOTFILE_NAME = "Vagrantfile"
|
||||
HOME_SUBDIRS = ["tmp", "boxes"]
|
||||
|
||||
# Initialize class variables used
|
||||
@@persisted_vm = nil
|
||||
|
@ -16,6 +17,7 @@ module Vagrant
|
|||
def load!
|
||||
load_root_path!
|
||||
load_config!
|
||||
load_home_directory!
|
||||
load_vm!
|
||||
end
|
||||
|
||||
|
@ -34,6 +36,20 @@ module Vagrant
|
|||
Config.execute!
|
||||
end
|
||||
|
||||
def load_home_directory!
|
||||
home_dir = File.expand_path(Vagrant.config.vagrant.home)
|
||||
|
||||
dirs = HOME_SUBDIRS.collect { |path| File.join(home_dir, path) }
|
||||
dirs.unshift(home_dir)
|
||||
|
||||
dirs.each do |dir|
|
||||
next if File.directory?(dir)
|
||||
|
||||
logger.info "Creating home directory since it doesn't exist: #{dir}"
|
||||
FileUtils.mkdir_p(dir)
|
||||
end
|
||||
end
|
||||
|
||||
def load_vm!
|
||||
File.open(dotfile_path) do |f|
|
||||
@@persisted_vm = Vagrant::VM.find(f.read)
|
||||
|
|
|
@ -27,6 +27,31 @@ class EnvTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
context "loading home directory" do
|
||||
setup do
|
||||
@home_dir = File.expand_path(Vagrant.config.vagrant.home)
|
||||
|
||||
File.stubs(:directory?).returns(true)
|
||||
FileUtils.stubs(:mkdir_p)
|
||||
end
|
||||
|
||||
should "create each directory if it doesn't exist" do
|
||||
create_seq = sequence("create_seq")
|
||||
File.stubs(:directory?).returns(false)
|
||||
Vagrant::Env::HOME_SUBDIRS.each do |subdir|
|
||||
FileUtils.expects(:mkdir_p).with(File.join(@home_dir, subdir)).in_sequence(create_seq)
|
||||
end
|
||||
|
||||
Vagrant::Env.load_home_directory!
|
||||
end
|
||||
|
||||
should "not create directories if they exist" do
|
||||
File.stubs(:directory?).returns(true)
|
||||
FileUtils.expects(:mkdir_p).never
|
||||
Vagrant::Env.load_home_directory!
|
||||
end
|
||||
end
|
||||
|
||||
context "loading config" do
|
||||
setup do
|
||||
@root_path = "/foo"
|
||||
|
@ -69,6 +94,7 @@ class EnvTest < Test::Unit::TestCase
|
|||
Vagrant::Env.expects(:load_config!).once
|
||||
Vagrant::Env.expects(:load_vm!).once
|
||||
Vagrant::Env.expects(:load_root_path!).once
|
||||
Vagrant::Env.expects(:load_home_directory!).once
|
||||
Vagrant::Env.load!
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue