Skip to content
This repository

If share_folder doesn't exist, create it #604

Closed
dkingofpa opened this Issue December 21, 2011 · 4 comments

3 participants

David King Mitchell Hashimoto Hayden
David King

When I specify a share_folder in my vagrantfile like so

config.vm.share_folder("www", "/vagrant/www", "./www", :owner => "www-data", :group => "www-data")

vagrant will error out:

dking@desktop78 ~/projects/vagrant-librarian $ vagrant up
There was a problem with the configuration of Vagrant. The error message(s)
are printed below:

vm:
* Shared folder host path for 'www' doesn't exist: ./www

I would like to see vagrant just create the missing host path. Committing an empty folder with a placeholder file into my git repo isn't the answer. In the mean time, this is how I'm working around the limitation in my vagrantfile:

if not FileTest::directory?("./www")
  Dir::mkdir("./www")
end
config.vm.share_folder("www", "/vagrant/www", "./www", :owner => "www-data", :group => "www-data")
Mitchell Hashimoto
Owner

Okay. I didn't want to make creating a shared folder the default because a simple typo could cause unexpected results (a folder would be created and it would look empty on the VM, which would not be expected).

Instead, I opted to get shared folders another option, the :create flag. If this flag is set to true (false by default), then it will attempt to create the folder if it does not exist. For example:

config.vm.share_folder "www", "/vagrant/www", "./www", :create => true

Simple enough?

Pushed, will be part of next release.

Mitchell Hashimoto mitchellh closed this January 08, 2012
David King

That'll do. Thanks Mitchell!

Hayden

What about?

vm:
* The following settings don't exist: share_folder
Mitchell Hashimoto
Owner

@haydenk You're probably using V2 config syntax, share_folder is from V1: http://docs.vagrantup.com/v2/vagrantfile/version.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.