Browse Source

data: fix crash when unwrapping vm

Fixes #5424
osy 2 years ago
parent
commit
f7e8a266d1
1 changed files with 7 additions and 3 deletions
  1. 7 3
      Platform/VMData.swift

+ 7 - 3
Platform/VMData.swift

@@ -161,11 +161,11 @@ import SwiftUI
         var loaded: (any UTMVirtualMachine)?
         var loaded: (any UTMVirtualMachine)?
         let config = try UTMQemuConfiguration.load(from: url)
         let config = try UTMQemuConfiguration.load(from: url)
         if let qemuConfig = config as? UTMQemuConfiguration {
         if let qemuConfig = config as? UTMQemuConfiguration {
-            loaded = try UTMQemuVirtualMachine(packageUrl: url, configuration: qemuConfig, isShortcut: isShortcut)
+            loaded = try UTMQemuVirtualMachine(packageUrl: url, configuration: qemuConfig, isShortcut: isShortcut(url))
         }
         }
         #if os(macOS)
         #if os(macOS)
         if let appleConfig = config as? UTMAppleConfiguration {
         if let appleConfig = config as? UTMAppleConfiguration {
-            loaded = try UTMAppleVirtualMachine(packageUrl: url, configuration: appleConfig, isShortcut: isShortcut)
+            loaded = try UTMAppleVirtualMachine(packageUrl: url, configuration: appleConfig, isShortcut: isShortcut(url))
         }
         }
         #endif
         #endif
         guard let vm = loaded else {
         guard let vm = loaded else {
@@ -279,8 +279,12 @@ extension VMData: Hashable {
 extension VMData {
 extension VMData {
     /// True if the .utm is loaded outside of the default storage
     /// True if the .utm is loaded outside of the default storage
     var isShortcut: Bool {
     var isShortcut: Bool {
+        isShortcut(pathUrl)
+    }
+    
+    func isShortcut(_ url: URL) -> Bool {
         let defaultStorageUrl = UTMData.defaultStorageUrl.standardizedFileURL
         let defaultStorageUrl = UTMData.defaultStorageUrl.standardizedFileURL
-        let parentUrl = pathUrl.deletingLastPathComponent().standardizedFileURL
+        let parentUrl = url.deletingLastPathComponent().standardizedFileURL
         return parentUrl != defaultStorageUrl
         return parentUrl != defaultStorageUrl
     }
     }