Skip to content

Commit

Permalink
vm: fix clone incorrect behaviour
Browse files Browse the repository at this point in the history
The name was not saved and the wrong VM had its ID changed.
  • Loading branch information
osy committed Dec 21, 2022
1 parent 56de8cf commit 05bb6d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion Managers/UTMVirtualMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,17 @@ extension UTMVirtualMachine: ObservableObject {
}

/// Called when we have a duplicate UUID
@MainActor func changeUuid(to uuid: UUID) {
@MainActor func changeUuid(to uuid: UUID, name: String? = nil) {
if let qemuConfig = config.qemuConfig {
qemuConfig.information.uuid = uuid
if let name = name {
qemuConfig.information.name = name
}
} else if let appleConfig = config.appleConfig {
appleConfig.information.uuid = uuid
if let name = name {
appleConfig.information.name = name
}
} else {
fatalError("Invalid configuration.")
}
Expand Down
4 changes: 2 additions & 2 deletions Platform/UTMData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ class UTMData: ObservableObject {
guard let newVM = UTMVirtualMachine(url: newPath) else {
throw NSLocalizedString("Failed to clone VM.", comment: "UTMData")
}
await vm.changeUuid(to: UUID())
try await vm.saveUTM()
await newVM.changeUuid(to: UUID(), name: newName)
try await newVM.saveUTM()
var index = await virtualMachines.firstIndex(of: vm)
if index != nil {
index! += 1
Expand Down

0 comments on commit 05bb6d3

Please sign in to comment.