From 144c874b5a8b5b451f4683c2a9c9154ebb453773 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 15 Apr 2014 14:03:51 -0700 Subject: [PATCH] providers/docker: process-level lock on copying default Vagrantfile --- lib/vagrant/environment.rb | 2 +- plugins/providers/docker/provider.rb | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 59d484675..7c9600488 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -373,7 +373,7 @@ module Vagrant # Mark that we have a lock @locks[name] = true - yield + return yield ensure # We need to make sure that no matter what this is always # reset to false so we don't think we have a lock when we diff --git a/plugins/providers/docker/provider.rb b/plugins/providers/docker/provider.rb index 69dd43d8a..0180d682e 100644 --- a/plugins/providers/docker/provider.rb +++ b/plugins/providers/docker/provider.rb @@ -52,8 +52,17 @@ module VagrantPlugins # we don't write into our installation dir (we can't). default_path = File.expand_path("../hostmachine/Vagrantfile", __FILE__) vf_path = @machine.env.data_dir.join("docker-host", "Vagrantfile") - vf_path.dirname.mkpath - FileUtils.cp(default_path, vf_path) + begin + if !vf_path.file? + @machine.env.lock("docker-provider-hostvm") do + vf_path.dirname.mkpath + FileUtils.cp(default_path, vf_path) + end + end + rescue Vagrant::Errors::EnvironmentLockedError + # Lock contention, just retry + retry + end # Set the machine name since we hardcode that for the default host_machine_name = :default