Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Create host directory when using SyncFolders if it doesn't exist #17

Merged
merged 4 commits into from
Aug 29, 2013
Merged

Create host directory when using SyncFolders if it doesn't exist #17

merged 4 commits into from
Aug 29, 2013

Conversation

chooper
Copy link

@chooper chooper commented Mar 25, 2013

Fixes #16

Includes error handling, such as:

$ bundle exec vagrant up --provider=aws
...
[default] Rsyncing folder: /tmp/docker/cant_write/ => ~/docker
There was an error when attempting to create a shared host folder.
Please inspect the error message below for more info.

Host path: /tmp/docker/cant_write/
Error: mkdir: cannot create directory `/tmp/docker': Permission denied

Also fixes a minor typo in the English locale for the rsync error message.

@mitchellh
Copy link
Owner

Unfortunately mkdir is not cross-platform safe. The biggest group of Vagrant users is on Windows. Instead, you should use FileUtils.mkdir_p and catch Errno::EPERM (I think, maybe EACCESS, I forget).

Otherwise, great patch. :)

@chooper
Copy link
Author

chooper commented Mar 25, 2013

Thanks for the comments! I'm swamped today but I think I can update the patch within the next 24-48 hours

@chooper
Copy link
Author

chooper commented Mar 25, 2013

Had some time on the train to update this :)

# Create the host path if it doesn't exist
begin
FileUtils::mkdir_p(hostpath)
rescue Exception => err

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unlikely that you want to rescue Exception here. You probably want StandardError, as the former rescues exciting exceptions like SyntaxError and SignalException. This can be simplified to rescue => err.

@chooper
Copy link
Author

chooper commented Mar 28, 2013

Thanks for the advice @titanous. I've since updated this PR

@mitchellh
Copy link
Owner

This looks good. One more thing: The shared folder should only be created if the :created option is set. Otherwise, validation should actually pick up and error (Vagrant core handles).

See here: https://github.com/mitchellh/vagrant/blob/c1f53a4ace1a29309032952da3c9bc658314fda0/plugins/providers/virtualbox/action/share_folders.rb#L55

@tralamazza tralamazza merged commit 5ab7862 into mitchellh:master Aug 29, 2013
@tralamazza
Copy link
Collaborator

I've added the :create flag check, thanks for the PR

tralamazza added a commit that referenced this pull request Aug 29, 2013
dldinternet pushed a commit to dldinternet/vagrant-aws that referenced this pull request Aug 29, 2013
@chooper chooper deleted the syncfolders_no_host_dir branch September 14, 2013 21:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SyncFolders fails when host directory does not exist
4 participants