Skip to content

Commit

Permalink
Fix Linux VM with downloaded install image not booting up
Browse files Browse the repository at this point in the history
  • Loading branch information
insidegui committed Aug 21, 2024
1 parent 1811cb7 commit 4809ae8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
4 changes: 4 additions & 0 deletions VirtualCore/Source/Models/VBVirtualMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ public extension VBVirtualMachine {
let metaData = try PropertyListEncoder.virtualBuddy.encode(metadata)
try write(metaData, forMetadataFileNamed: Self.metadataFilename)

try saveInstallData()
}

func saveInstallData() throws {
if let installRestoreData {
try write(installRestoreData, forMetadataFileNamed: Self.installRestoreFilename)
} else {
Expand Down
22 changes: 11 additions & 11 deletions VirtualUI/Source/Installer/VMInstallationViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ final class VMInstallationViewModel: ObservableObject {
do {
let restoreData = try PropertyListEncoder.virtualBuddy.encode(restorableState)
machine.installRestoreData = restoreData
try machine.saveMetadata()
try machine.saveInstallData()
self.machine = machine
} catch {
assertionFailure("Failed to save install restore data: \(error)")
Expand Down Expand Up @@ -246,7 +246,10 @@ final class VMInstallationViewModel: ObservableObject {
let d = VBDownloader(with: library, cookie: data.cookie)
self.downloader = d

d.$state.sink { [weak self] state in
d.$state
.receive(on: DispatchQueue.main)
.sink
{ [weak self] state in
guard let self = self else { return }
switch state {
case .done(let localURL):
Expand All @@ -261,21 +264,18 @@ final class VMInstallationViewModel: ObservableObject {
d.startDownload(with: url)
}

@MainActor
func handleDownloadCompleted(with fileURL: URL) {
downloader = nil

data.installImageURL = fileURL

Task {
await MainActor.run {
do {
try updateModelInstallerURL(with: fileURL)
do {
try updateModelInstallerURL(with: fileURL)

goNext()
} catch {
state = .error("Failed to update the virtual machine settings after downloading the installer. \(error)")
}
}
goNext()
} catch {
state = .error("Failed to update the virtual machine settings after downloading the installer. \(error)")
}
}

Expand Down

0 comments on commit 4809ae8

Please sign in to comment.