Check for empty result from fog-libvirt volumes

The fog-libvirt volumes filter behaves differently than the others in
that it returns an empty volume object if nothing is found. This has the
potential to change in the future so guard against an empty result as
well by checking if the assigned first element is nil.
This commit is contained in:
Chris Crebolder 2020-04-23 16:42:45 -04:00 committed by Darragh Bailey
parent 86aac4ce9c
commit 34d933deea
2 changed files with 4 additions and 3 deletions

View File

@ -28,7 +28,7 @@ module VagrantPlugins
domain_volume = env[:machine].provider.driver.connection.volumes.all(
name: @name
).first
raise Errors::DomainVolumeExists if domain_volume.id
raise Errors::DomainVolumeExists if domain_volume && domain_volume.id
# Get path to backing image - box volume.
box_volume = env[:machine].provider.driver.connection.volumes.all(

View File

@ -63,9 +63,10 @@ module VagrantPlugins
# locking all subsequent actions as well.
@@lock.synchronize do
# Don't continue if image already exists in storage pool.
break if env[:machine].provider.driver.connection.volumes.all(
box_volume = env[:machine].provider.driver.connection.volumes.all(
name: env[:box_volume_name]
).first.id
).first
break if box_volume && box_volume.id
# Box is not available as a storage pool volume. Create and upload
# it as a copy of local box image.