lib/vagrant/action/builtin/box_add.rb in vagrant-unbundled-2.3.3.0 vs lib/vagrant/action/builtin/box_add.rb in vagrant-unbundled-2.3.6.0
- old
+ new
@@ -4,10 +4,11 @@
require "uri"
require "vagrant/box_metadata"
require "vagrant/util/downloader"
require "vagrant/util/file_checksum"
+require "vagrant/util/file_mutex"
require "vagrant/util/platform"
module Vagrant
module Action
module Builtin
@@ -477,15 +478,24 @@
env[:ui].info(I18n.t("vagrant.actions.box.download.resuming"))
end
end
begin
- d.download!
- rescue Errors::DownloaderInterrupted
- # The downloader was interrupted, so just return, because that
- # means we were interrupted as well.
- @download_interrupted = true
- env[:ui].info(I18n.t("vagrant.actions.box.download.interrupted"))
+ mutex_path = d.destination + ".lock"
+ Util::FileMutex.new(mutex_path).with_lock do
+ begin
+ d.download!
+ rescue Errors::DownloaderInterrupted
+ # The downloader was interrupted, so just return, because that
+ # means we were interrupted as well.
+ @download_interrupted = true
+ env[:ui].info(I18n.t("vagrant.actions.box.download.interrupted"))
+ end
+ end
+ rescue Errors::VagrantLocked
+ raise Errors::DownloadAlreadyInProgress,
+ dest_path: d.destination,
+ lock_file_path: mutex_path
end
Pathname.new(d.destination)
end