Skip to content

Commit

Permalink
data: update stale vm when container path changes
Browse files Browse the repository at this point in the history
Fixes #4392
  • Loading branch information
osy committed Sep 10, 2022
1 parent 8bbadc7 commit 39b8c17
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Platform/UTMData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,19 @@ class UTMData: ObservableObject {
let vm = UTMVirtualMachine(url: file)
if let vm = vm {
if uuidHasCollision(with: vm, in: list) {
await uuidRegenerate(for: vm)
if let index = list.firstIndex(where: { $0 is UTMWrappedVirtualMachine && $0.id == vm.id }) {
// we have a stale VM with the same UUID, so we replace that entry with this one
list[index] = vm
// update the registry with the new bookmark
try? await vm.updateRegistryFromConfig()
} else {
// duplicate is not stale so we need a new UUID
await uuidRegenerate(for: vm)
list.insert(vm, at: 0)
}
} else {
list.insert(vm, at: 0)
}
list.insert(vm, at: 0)
} else {
logger.error("Failed to create object for \(file)")
}
Expand Down

0 comments on commit 39b8c17

Please sign in to comment.