Skip to content

Commit b50c397

Browse files
author
GitHub Copilot
committed
virtualbox/cap: fix path comparison for extra disks in snapshots
When a VirtualBox VM has snapshots, the primary disk location may be under the Snapshots subdirectory, causing path comparison with other disks to fail. Update the comparison logic to also consider the parent directory of the Snapshots folder, allowing existing extra disks to be found and preventing attempts to recreate them that would result in VERR_ALREADY_EXISTS errors. Fixes #13352 Signed-off-by: GitHub Copilot <[email protected]>
1 parent f2960d5 commit b50c397

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

plugins/providers/virtualbox/cap/configure_disks.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,24 @@ def self.handle_configure_disk(machine, disk, controller_name)
128128
# associated with the guest, since disk names are not unique
129129
# globally to VirtualBox.
130130
primary = storage_controllers.get_primary_attachment
131+
132+
# Determine candidate directories for the primary disk. When a VM
133+
# has snapshots, VirtualBox may place snapshot differencing disks
134+
# under a 'Snapshots' subdirectory while original disks live in the
135+
# parent VM folder. For example:
136+
# - /.../test_default_xxx/data.vdi
137+
# - /.../test_default_xxx/Snapshots/{uuid}.vdi
138+
# In that case, primary[:location] may point to the Snapshots path
139+
# so we should also consider the parent directory when attempting
140+
# to match existing extra disks by location.
141+
primary_dir = File.dirname(primary[:location])
142+
primary_dir_candidates = [primary_dir]
143+
if File.basename(primary_dir) == "Snapshots"
144+
primary_dir_candidates << File.dirname(primary_dir)
145+
end
146+
131147
existing_disk = machine.provider.driver.list_hdds.detect do |d|
132-
File.dirname(d["Location"]) == File.dirname(primary[:location]) &&
148+
primary_dir_candidates.include?(File.dirname(d["Location"])) &&
133149
d["Disk Name"] == disk.name
134150
end
135151

0 commit comments

Comments
 (0)